Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AnjaliManhas/ebd50a6fe15b2cbbb7a1a1603952fbc9 to your computer and use it in GitHub Desktop.
Save AnjaliManhas/ebd50a6fe15b2cbbb7a1a1603952fbc9 to your computer and use it in GitHub Desktop.
Two Sum Problem- LeetCode- Given an array of integers of the two numbers such that they add up to a specific target. You may assume that each input would have one solution, and you may not use the same element twice.
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> arr;
for (int i=0; i < nums.size(); i++){
int rem = target - nums[i];
for (int j=0; j < nums.size(); j++){
if (rem == nums[j] && j!=i){
arr.push_back(i);
arr.push_back(j);
i= nums.size();
}
}
}
return arr;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment