Get a TLE...


  • 0
    D
    class Solution {
        func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
            
            var numsDic = Dictionary<String, Int>()
            
            for i in 0..<nums.count {
                
                numsDic.updateValue(i, forKey: "\(nums[i])")
            }
            
            
            for value in nums {
                let tmp = target - value
                let key = "\(tmp)"
                let index = nums.index(of: value)!
                
                if numsDic[key] != nil && index != numsDic[key]{
                    
                    return [index, numsDic[key]!]
                }
            }
            
            
            return []
        }
    }
    

Log in to reply
 

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