* 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:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
首先需要遍歷數組找到兩個數的和為target 的元素,創建一個 hashMap 因為hashMap 的get()方法的時間復雜度是O(1) 最多 也是O(logn),將目標數target減去當前數組的元素的值存入map里以這個值為key 它的下標為value,,若map里有這個元素,表示target = 當前元素+map里存在的這個數,分別返回元素的下標即可。