My Swift Solution


  • 0
    J
    class Solution {
        func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
            
            for (index,value) in nums.enumerated() {
                for j in index+1 ..< nums.count {
                    if value + nums[j] == target {
                        return [index,j]
                    }
                 }
            }
            return []
            
        }
    }
    

Log in to reply
 

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