mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
14 lines
278 B
C++
14 lines
278 B
C++
public:
|
|
vector<int> twoSum(vector<int>& nums, int target){
|
|
unordered_map<int,int>hash;
|
|
for(int i=0;i<nums.size();++i){
|
|
int comp = target - nums[i];
|
|
if(hash.find(complement) != hash.end(){
|
|
return {hash[complement],i};
|
|
hash[nums[i]] = i;
|
|
|
|
}
|
|
}
|
|
}
|
|
|