Leetcode 338. Counting Bits | Bit Manipulation | Brute Force to Optimal | 2 Solutions with full code
Vložit
- čas přidán 28. 02. 2022
- Connect with me on LinkedIn : / alisha-parveen-80579850
Check out our other playlists:
Dynamic Programming:
• Dynamic Programming
Trees:
• Trees
Heaps and Maps:
• Heaps and Maps
Arrays and Maths:
• Arrays and Maths
Bit Manipulation:
• Bit Manipulation
Greedy Algorithms:
• Greedy Algorithms
Sorting and Searching:
• Sorting and Searching
Strings:
• Strings
Linked Lists:
• Linked Lists
Stack and Queues:
• Stacks and Queues
Two Pointers:
• Two pointers
Graphs, BFS, DFS:
• Graphs, DFS, BFS
Backtracking:
• Backtracking
Non- DSA playlists:
Probability:
• Probability
SQL-Basic Join functions:
• SQL - Basic JOIN Funct...
SQL-Basic Aggregate functions:
• SQL-Basic Aggregate Fu...
vectorans(n+1,0);
for(int i=0;i
Can you please tell me how the binary value of a number is getting assigned to the variable 'num'?
This makes much more sense
instead of % 2 we can use &1 which return 1 if bit is 1 and 0 when bit is 0;
and we can right shift num by 1
class Solution {
public:
vector countBits(int n) {
vector ans;
for(int i=0;i>1;
}
ans.push_back(sum);
}
return ans;
}
};
Awesome job Alisha. I just found out about this channel and I'm definitely here to stay.
Yours is the simpleest explanation I found
Thankyou for super easy explanation
the way you explained the solution was awesome dear
Excellent Explanation Alisha. Subscribed ;)
Awesome ...
ty
Nice explanation 🔥
Nice explanation 🎇
Good Work
Thanks
thanks
Op❤
N is given in decimal but when we are iterating over N how we can find 1 and 0s?
how diving the num by 2 removing 1 value from the unit place i think it's done by dividing it by 10
1011/2 = 505
1011/10 = 101 and that's what we want here
yrr aap muche kaat leti