Комментарии:
Yay, someone I can understand
Ответитьgood
ОтветитьUnderrated!
ОтветитьThank you for providing such fantastic content
ОтветитьThank you
ОтветитьYour the best bro. The problem seems so easy with the way you explain it. Thanks again. Also this is my solution in python based on your approach
class Solution:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
start = 0
middle = 0
end = len(nums ) - 1
while middle <= end:
if nums[middle] == 0:
nums[start], nums[middle] = nums[middle], nums[start]
start += 1
middle += 1
elif nums[middle] == 1:
middle += 1
elif nums[middle] == 2:
nums[end], nums[middle] = nums[middle], nums[end]
end -= 1
Your the best bro. The problem seems so easy with the way you explain it. Thanks again. Also this is my solution in python based on your approac
Ответитьvery good explanation! keep up the good work
ОтветитьWhy not just count zeroes and ones and refill the array in place? 😂
ОтветитьBest solution I've seen for this problem. This channel is so underrated.
Ответитьyour explanations are really amazing. In fact, best so far :) Please make more videos :)
Ответитьwhy we are not incrementing mid when it is arr[mid] is 2?
ОтветитьThanks
ОтветитьThank you soo much ❤❤
ОтветитьThank you, ploblem solved. love you
😁
i used selection sort
ОтветитьGreat explaination! But I noticed one thing, in the first example, first swap is wrong as middle was at 0, so swap between start and middle should take place and start and middle should move and not between middle and end i.e 0 and 2 what you did because middle was not at 2.
Ответить💯❤
Ответитьsir, I actually used in-built sort function, in leetcode ie. sort(nums.begin(),nums.end()), and it said said, u beat 100% users with c++. Can we do this or not???
Ответитьwhy don't we just loop through the entire array and count the 0's and 1's in seperate variables, then loop the array again and replace number of 0, 1, 2 in that order.
ОтветитьVERY NICE EXPLANATION WITH CLARITY . THANKS BHAIYA .
ОтветитьGreat explanation, good work
ОтветитьPicture perfect mate!
Thanks.
best explanation Sir! I didn't watch the coding part before solving the problem. So I implemented it using if-else statements.After solving, I watched the last part. I found out you wrote it using switch cases. Understanding both versions make me confident in coding
ОтветитьJava Solution (Beats 100 %)
class Solution {
public void sortColors(int[] nums) {
int n = nums.length ;
int[] arr = new int[3] ;
int element = 0 ;
for(int i = 0 ; i < n ; i++){
element = nums[i] ;
arr[element]++ ;
}
int count = 0 ;
int k = 0 ;
for(int i = 0 ; i<3 ; i++){
count = arr[i] ;
while(count > 0){
nums[k] = i ;
k++ ;
count-- ;
}
}
}
}
c++
class Solution {
public:
void sortColors(vector<int>& nums) {
int start = 0;
int middle = 0;
int end = nums.size() - 1;
while (middle <= end) {
if (nums[middle] == 0) {
swap(nums[start], nums[middle]);
start++;
middle++;
} else if (nums[middle] == 1) {
middle++;
} else if (nums[middle] == 2) {
swap(nums[middle], nums[end]);
end--;
}
}
}
void swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
};
❤
ОтветитьMan that’s the best explanation. I saw the coded solution for this problem which is same as yours but couldn’t wrap my head around it. Now I got it! Thank you!
ОтветитьThanks man this helped me a lot, loved your energy throughout the problem.
ОтветитьYOU MADE IT THE SIMPLEST TO UNDERSTAND WITHOUT COMPLICATING THINGS!!!!! HAT'S OFF TO YOU!
ОтветитьToo difficult to understand what he says because of his accent.
ОтветитьThis is better than strivers i watched him then i watched you had a strongn feeling this would be good🎉
Ответитьyou are super good
ОтветитьBest solution I've seen for this problem. This channel is so underrated.
Ответитьreally very good explanation. you made it so easy
Ответитьbhai whai is vailya
ОтветитьOP
ОтветитьThanks Brother❤
ОтветитьGREAT VIDEO
Ответитьwow. such a simple and wonderful solution
ОтветитьHi Nikhil!! I am so glad to find this channel. The presentation and the way you explain things in a simple and easy-to-understand manner are awesome. Last but not least, the dry run and the explanation of the code are what I have been looking for so long. I finally found your channel. Thanks a ton, brother.
ОтветитьWow wow. I watched tons of video on DNF algoritm, I didn't understood whay they are saying. You explaind it excellently.
Ответитьthanks a tonn very clear explanation !! beginner friendly
Ответитьwhy XOR swapping is not working here ???????????????????????????
ОтветитьNice video...thanku sir
ОтветитьThanks Nikhil sir, you really made the concept easy!
ОтветитьWhy did you make a special function swap ??
ОтветитьThis is nice explanation unlike others who tried to explain the algorithm with out explaining the logic
Ответить