https://leetcode.com/problems/two-sum/
1. Use hashtable/hashmap:
// 16 ms 10.3 MBclass Solution {public:vector<int> twoSum(vector<int>& nums, int target) {unordered_map<int, int> hashmap; //nums, index_of_numsint n = nums.size();for(int i = 0; i < n; i++)hashmap[nums[i]] = i;for(int i = 0; i < n; i++){unordered_map<int, int>::iterator got = hashmap.find(target-nums[i]);if(got != hashmap.end() && (i != got->second))return {i, got->second};}return {};}};
