Created
March 27, 2020 01:25
-
-
Save ajbeach2/25ee8fd52687b60350442ba92250c219 to your computer and use it in GitHub Desktop.
This file contains 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 arr[] ={0,0,0}; | |
for(int i = 0; i < nums.size(); i++) | |
arr[nums[i]]++; | |
int next = 0; | |
for(int i = 0; i < nums.size(); i++){ | |
while(arr[next] > 0){ | |
nums[i] = next; | |
arr[next]--; | |
i++; | |
} | |
next++; | |
i--; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment