两数之和
classSolution{
functwoSum(_nums: [Int],_target: Int) -> [Int] {
let count = nums.count
if count <= 0 {
return []
}
var dic: [Int:Int] = [:]
for i in 0...count-1 {
let value = nums[i]
if let b = dic[target-value] {
return [i,b]
}
dic[value] = i
}
return []
}
}
网友评论