[LeetCode] 1. Two Sum [Easy]
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Analyse:
由於題目假設必有一解, 故nums中的element之中必有一個A與B, 其A等於target - B.
在for迴圈中利用[Int: Int] Dictionary 儲存每個nums[i]的value與Index,
若找到一個nums[i]其 Dictionary [target - nums[i]] != nil 則為其解..
Solution:
Last updated