article thumbnail image
Published 2022. 8. 30. 13:14
 

Sort Colors - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

void sortColors(vector<int>& nums){
	int pivovIndex = 0;
	int currentColor = 0;
	while(pivovIndex < nums.size()){
		for(int i = pivovIndex; i < nums.size(); i++){
			if(nums[i] == currentColor){
				std::swap(nums[pivovIndex], nums[i]);
				pivovIndex++;
			}
		}
		currentColor++;
	}
}

'Problem set' 카테고리의 다른 글

[LeetCode] Maximum Subarray - Kadane Algorithm  (0) 2022.09.21
[LeetCode] Sort-Array-By-Parity-ii  (0) 2022.08.26
[LeetCode] Find Pivot Index  (0) 2022.08.26
[LeetCode] Move Zeroes  (0) 2022.08.26
[백준] 1967 트리의 지름  (0) 2021.02.20
복사했습니다!