LeetCode 1
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> res;
unordered_map<int,int> hash_map;
for(int i=0;i<nums.size();i++){
int another=target-nums[i];
if(hash_map.count(another))
{
res={
hash_map[another],i};
return res;
}
hash_map[nums[i]]=i;
}
return {
};
}
};
LeetCode 49
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>