mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
18 lines
472 B
C
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;
|
||
|
}
|
||
|
};
|