Created
April 6, 2017 15:23
-
-
Save s4553711/4007094099ec92d503fa922693f8028f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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