티스토리 뷰
https://leetcode.com/problems/sort-colors/
[leetcode][C++] sort colors
class Solution {
public:
void sortColors(vector<int>& nums) {
int low = 0;
int high = nums.size() - 1;
for (int i = 0; i <= high;) {
if (nums[i] == 0) {
swap(nums[i], nums[low]);
low++; i++;
}
else if (nums[i] == 2) {
swap(nums[i], nums[high]);
high--;
}
else i++;
}
}
};
'Problem Solving' 카테고리의 다른 글
[leetcode][C++] rotate image (0) | 2021.10.16 |
---|---|
[백준][C++] 17779 게리맨더링2 (0) | 2021.10.16 |
[leetcode][C++][Java] jump game (0) | 2021.10.15 |
[leetcode][C++] search in rotated sorted array (0) | 2021.10.06 |
[leetcode][C++] generate parentheses (0) | 2021.10.05 |
댓글