Leetcode day1

This commit is contained in:
2026-01-25 12:41:33 +05:30
parent 686d174f19
commit 245116d181
14 changed files with 168 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
class Solution{
public:
vector<int> twoSum(vector<int> &nums, int target) {
unordered_map<int, int> hash;
for (int i = 0; i < nums.size(); i++) {
hash[nums[i]] = i;
}
for (int i = 0; i < nums.size(); i++) {
int comp = target - nums[i];
if (hash.find(comp) != hash.end() && hash[comp] != i) {
return {i, hash[comp]};
}
}
return {};
}
};