The one liner solution to this with XOR is def minBitFlips(self, start: int, goal: int) -> int: return bin(start^goal).count("1") For Python 3.10+, the code can be simplified even further using bit_count method. def minBitFlips(self, start: int, goal: int) -> int: return (start^goal).bit_count()
Thanks for your video - upvoted! Oneliners for this task also might be interesting: 1. (v^u).bit_count() 2. bin(v^u).count('1') 3. sum(map(int,f'{v^u:b}')) 4. (f:=lambda q:q and q%2+f(q>>1))(v^u)
11:58 The mom joke caught me off guard 💀
We have fun here
@@ZeroTrunks That's what your mom said to me last night...haha
(Sorry big guy, just a joke...)
All of us... 🤣
The one liner solution to this with XOR is
def minBitFlips(self, start: int, goal: int) -> int:
return bin(start^goal).count("1")
For Python 3.10+, the code can be simplified even further using bit_count method.
def minBitFlips(self, start: int, goal: int) -> int:
return (start^goal).bit_count()
Thanks for your video - upvoted!
Oneliners for this task also might be interesting:
1. (v^u).bit_count()
2. bin(v^u).count('1')
3. sum(map(int,f'{v^u:b}'))
4. (f:=lambda q:q and q%2+f(q>>1))(v^u)
"Perhaps you are making a scale to weigh your mom""
I had to use a different solution because of this....
extra challenge: if you're using python, do it in one line
Neetcode is pretty chill...... with random spurs of Mom jokes xD 🤣🤣
Loop through 0 to 31 and Just check if (1
diabolical use case of 1000 bit number ☠
meanwhile I made functions to convert an int to binary, then pad zeros to the smaller number, then compare each character 😭
us :v
same. but its fine. fuck bit manipulation
The mom joke caught me offguard
AND1
"perhaps you're trying to build a scale to weigh your mom" hahahahahhaahaha
is it just me or video is speeded up a little?
First!
honestly the bitwise & with 1 and then bit shift is much more intruitive and readable then the last solution