728x90
반응형
Solution
- Brute Force
- Time Complexity : O(N^2)
- Space Omplexity : O(1)
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> RetVal;
for (int i = 0; i != nums.size(); ++i)
{
for (int j = i + 1; j != nums.size(); ++j)
{
if ((nums[i] + nums[j]) == target)
{
RetVal.push_back(i);
RetVal.push_back(j);
return RetVal;
}
}
}
RetVal.push_back(-1);
RetVal.push_back(-1);
return RetVal;
}
};
728x90
반응형
'개념공부 > C, C++, IDE' 카테고리의 다른 글
[C++ STL] unordered_map (0) | 2023.01.16 |
---|---|
[C++ STL] map (0) | 2023.01.16 |
[LeetCode] 1030. Matrix Cells in Distance Order, C++ (0) | 2023.01.09 |
[C++] Unordered Map (작성 중) (0) | 2023.01.08 |
[C++] vector container (0) | 2023.01.06 |