Initial commit

This commit is contained in:
2022-07-26 16:15:18 +05:30
commit cef4c4dcc4
65 changed files with 1806 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
class Solution {
public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length - 1; i++)
for (int j = i + 1; j < nums.length; j++)
if (target - nums[i] == nums[j])
return new int[] { i, j };
return new int[] { -1, -1 };
}
}

18
Easy/two-sum/solution.cpp Normal file
View File

@@ -0,0 +1,18 @@
class Solution {
public:
std::vector<int> twoSum(std::vector<int> &nums, int target) {
std::unordered_map<int, int> hmap;
for (int i = 0; i < nums.size(); ++i) {
int diff = target - nums[i];
if (hmap.find(diff) != hmap.end()) {
return {hmap[diff], i};
} else {
hmap[nums[i]] = i;
}
}
return {-1, -1};
}
};