Accepted Swift O(n2) solution


  • 0
    F
        func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
            for (index, first) in nums.enumerated(){
                let next = index + 1
                for indexPlus in next...nums.count-1 {
                    if nums[indexPlus] == target - first {
                        return  [index, indexPlus]
                    }
                }
            }
            return []
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.