func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
guard nums.count >= 2 else {
return [0]
}
var tempHash: [Int : Int] = [:]
var result : [Int] = []
for (i, value) in nums.enumerated() {
if let index = tempHash[target - value]{
result.append(index)
result.append(i)
return result
}
tempHash[value] = i
}
return [0]
}

还可以提高2%,但想象力贫穷了
网友评论