美文网首页
1.两数之和 LeetCode

1.两数之和 LeetCode

作者: 出来遛狗了 | 来源:发表于2018-11-02 10:42 被阅读0次
    image.png
    func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
            if nums.count < 2{
                return [];
            }
            for i in 0..<nums.count - 1{
                let num1 = target - nums[i]
                for j in (i + 1)..<nums.count{
                    if nums[j] == num1{
                        return [i, j];
                    }
                }
            }
            return [];
        }
    

    相关文章

      网友评论

          本文标题:1.两数之和 LeetCode

          本文链接:https://www.haomeiwen.com/subject/qmuqxqtx.html