1. Two Sum
https://leetcode.com/problems/two-sum/description/
Solution
Brute Force
Use every element as an anchor and search its right element
时间复杂度:O(n^2) 空间复杂度:O(1)
Hash Map
Leverage the power of hashmap and store the number and its index in the map
When the map contain target - curNum, we know the search is complete
时间复杂度:O(n) 空间复杂度:O(n)
Last updated