728x90
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> answer;
for(int i = 0 ; i < nums.size() - 1 ; i++) {
for(int j = i+1 ; j < nums.size() ; j++) {
if(nums[i] + nums[j] == target) {
answer.push_back(i);
answer.push_back(j);
}
}
}
return answer;
}
};
'๐ Self Study > ๐ LeetCode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
LeetCode (Add two numbers) C++ (0) | 2022.01.07 |
---|---|
LeetCode (Employee Importance) C++ (0) | 2022.01.06 |
LeetCode (Sum of Left Leaves) C++ (0) | 2022.01.06 |