cpp-interview/Problems/LeetcodeProblems/two-sum.h
2018-02-09 21:47:58 +08:00

18 lines
472 B
C++

class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> sum;
for(auto i = 0; i < nums.size(); i++)
{
for(auto j = i+1; j < nums.size(); j++)
{
if(i == j) continue;
if(nums[i] + nums[j] != target) continue;
sum.push_back(i);
sum.push_back(j);
return sum;
}
}
return sum;
}
};