twoSum Algorithm : How to improve this?

前端 未结 22 2124
礼貌的吻别
礼貌的吻别 2021-02-06 01:38

I felt like doing an algorithm and found this problem on leetcode

Given an array of integers, find two numbers such that they add up to a specific target num

22条回答
  •  深忆病人
    2021-02-06 01:51

    Swift code with Time Complexity O(n) and Space complexity O(n):

    import UIKit
    
    class Solution{
        func twoSum(_ nums: [Int], _ target: Int) -> [Int]{
            var finalArray = [Int]()
            var newDictionary = [Int:Int]()
            for i in 0..

提交回复
热议问题