Sort Colors | Leetcode 75 | Live coding session 🔥🔥🔥

preview_player
Показать описание
Here is the solution to "Sort Colors" leetcode question. Hope you have a great time going through it.

1) 0:00 Explaining the problem out loud
2) 1:10 Algorithm walkthrough
3) 6:00 Coding

For discussion/feedback

PS : Please increase the speed to 1.25X
Рекомендации по теме
Комментарии
Автор

I have solved this few days before
Using the second method
This months questions are very easy

sreejith
Автор

One more solution by counting occurrence of each color

public void sortColors(int[] nums) {
int count0=0, count1=0, count2=0;

for(int i=0; i<nums.length; i++){

if(nums[i]==0)
count0++;

else if(nums[i]==1)
count1++;

else
count2++;
}

for(int i=0; i<count0; i++){
nums[i]=0;
}

for(int i=count0; i<(count0+count1); i++){
nums[i]=1;
}

for(int i=(count0+count1); i<nums.length; i++){
nums[i]=2;
}


}
}

sharoonaustin
Автор

are you going to prepare upsc.... you bookmark the

amitbajpai
visit shbcf.ru