Leetcode 75 Solution
This article provides solution to leetcode question 75 (sort-colors)
Access this page by simply typing in "lcs 75" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/sort-colors
Solution
class Solution {
public:
void sortColors(vector<int>& nums) {
int l = 0;
int r = nums.size() - 1;
for (int i = 0; i <= r; i++)
{
if (nums[i] == 0)
swap(nums[l++], nums[i]);
else if (nums[i] == 2)
swap(nums[r--], nums[i]), i--;
}
}
};