Skip to content

Instantly share code, notes, and snippets.

@Ram-1234
Created December 25, 2020 18:36
Show Gist options
  • Save Ram-1234/f5728edc89e4650c9e311afa9ec64bff to your computer and use it in GitHub Desktop.
Save Ram-1234/f5728edc89e4650c9e311afa9ec64bff to your computer and use it in GitHub Desktop.
Sort Colors
// JAVA CODE
class Solution {
public void sortColors(int[] nums) {
int zero=0,one=0,two=0;
for(int i:nums){
if(i==0) zero++;
if(i==1) one++;
if(i==2) two++;
}
int i=0;
while(zero-->0)
nums[i++]=0;
while(one-->0)
nums[i++]=1;
while(two-->0)
nums[i++]=2;
}
}
//////
INPUT
Input: nums = [2,0,2,1,1,0]
/////
OUTPUT
Output: [0,0,1,1,2,2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment