Skip to content

Instantly share code, notes, and snippets.

@ajbeach2
Created March 27, 2020 01:25
Show Gist options
  • Save ajbeach2/25ee8fd52687b60350442ba92250c219 to your computer and use it in GitHub Desktop.
Save ajbeach2/25ee8fd52687b60350442ba92250c219 to your computer and use it in GitHub Desktop.
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