Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created April 6, 2017 15:23
Show Gist options
  • Save s4553711/4007094099ec92d503fa922693f8028f to your computer and use it in GitHub Desktop.
Save s4553711/4007094099ec92d503fa922693f8028f to your computer and use it in GitHub Desktop.
class Solution {
public:
void sortColors(vector<int>& nums) {
int zeroI = 0, secndI = nums.size() - 1;
for(int i = 0; i < nums.size(); i++) {
while (nums[i] == 2 && i < secndI) swap(nums[i], nums[secndI--]);
while (nums[i] == 0 && i > zeroI) swap(nums[i], nums[zeroI++]);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment