## Solutions
### [[Hash Table]]
```python
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
num_dict = {}
for i, num in enumerate(nums):
complement = target - num
if complement in num_dict:
return[i, num_dict[complement]]
num_dict[num] = i
return []
```
1. initialize an empty hash table
2. iterate the array using enumerate to get both index and value [[Array#Iteration]]
1. find the **complement** by use target minus num
2. if the complement is in hash table, it means we find the two number's sum can be the target number, return their index
3. if the complement is not in array, store the index of current number and keeps going
4. if no pair is found after iteration, return an empty array
#### Complexity Analysis
- Time complexity: On because we iterate the array
- Space complexity: On because we need to store the whole array in hash map in the worst situation