Created
April 26, 2020 08:33
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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