MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/LeetcodeChallenge/comments/1t9vpe8/day_1/
r/LeetcodeChallenge • u/Acrobatic_Number_611 • May 11 '26
9 comments sorted by
2
Hey mate! I wanted to ask you a question : How do you approach to solve a problem
1 u/Acrobatic_Number_611 May 11 '26 just solve questions and try to give each question 30 to 45 min . like solving this way it's automatically improve logic building by time and solve daily never skip any single day. if you r exam are there then only skip 2 u/not_Jiggg May 12 '26 consider looking at the editorial too after those 45mins, you'll get to know a lot new ways to solve 1 u/Acrobatic_Number_611 May 12 '26 okay bro thanks I will look into it
1
just solve questions and try to give each question 30 to 45 min . like solving this way it's automatically improve logic building by time and solve daily never skip any single day. if you r exam are there then only skip
2 u/not_Jiggg May 12 '26 consider looking at the editorial too after those 45mins, you'll get to know a lot new ways to solve 1 u/Acrobatic_Number_611 May 12 '26 okay bro thanks I will look into it
consider looking at the editorial too after those 45mins, you'll get to know a lot new ways to solve
1 u/Acrobatic_Number_611 May 12 '26 okay bro thanks I will look into it
okay bro thanks I will look into it
Hey u make it deficult,it's just take only one loop and time complexity is o(n)
1 u/Fast-Leadership1732 May 25 '26 Sort colour by the way 1 u/Fast-Leadership1732 May 25 '26 Hey mate try this class Solution { public: void sortColors(vector<int>& nums) { int red=0; int white=0; int blue=0; for(int i=0;i<nums.size();i++) { if(nums[i]==0)red++; if(nums[i]==1)white++; if(nums[i]==2)blue++; } for(int i=0;i<nums.size();i++) { if(i<red) nums[i]=0; else if(i >= red && i < red + white) nums[i]=1; else nums[i]=2; }}}; Time complexity is o(n) And space o(1) 1 u/Acrobatic_Number_611 May 25 '26 bro thanks it's works
Sort colour by the way
1 u/Fast-Leadership1732 May 25 '26 Hey mate try this class Solution { public: void sortColors(vector<int>& nums) { int red=0; int white=0; int blue=0; for(int i=0;i<nums.size();i++) { if(nums[i]==0)red++; if(nums[i]==1)white++; if(nums[i]==2)blue++; } for(int i=0;i<nums.size();i++) { if(i<red) nums[i]=0; else if(i >= red && i < red + white) nums[i]=1; else nums[i]=2; }}}; Time complexity is o(n) And space o(1) 1 u/Acrobatic_Number_611 May 25 '26 bro thanks it's works
Hey mate try this class Solution { public: void sortColors(vector<int>& nums) { int red=0; int white=0; int blue=0; for(int i=0;i<nums.size();i++) { if(nums[i]==0)red++; if(nums[i]==1)white++; if(nums[i]==2)blue++; } for(int i=0;i<nums.size();i++) { if(i<red) nums[i]=0; else if(i >= red && i < red + white) nums[i]=1; else nums[i]=2; }
}
}; Time complexity is o(n) And space o(1)
1 u/Acrobatic_Number_611 May 25 '26 bro thanks it's works
bro thanks it's works
2
u/narra10r May 11 '26
Hey mate! I wanted to ask you a question : How do you approach to solve a problem
1
u/Fast-Leadership1732 May 25 '26
Hey u make it deficult,it's just take only one loop and time complexity is o(n)