Two-sum solution

This commit is contained in:
2025-12-06 10:00:23 +00:00
parent de106b2e33
commit 6363aeaed3
4 changed files with 57 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
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;
}
}
}