Minimum Bit Flips to Convert Number - Leetcode 2220 - Python

Поділитися
Вставка
  • Опубліковано 3 лис 2024

КОМЕНТАРІ • 22

  • @avoynath8653
    @avoynath8653 Місяць тому +26

    11:58 The mom joke caught me off guard 💀

    • @ZeroTrunks
      @ZeroTrunks Місяць тому

      We have fun here

    • @avoynath8653
      @avoynath8653 Місяць тому +2

      ​@@ZeroTrunks That's what your mom said to me last night...haha
      (Sorry big guy, just a joke...)

    • @business_central
      @business_central Місяць тому

      All of us... 🤣

  • @AlfredPros
    @AlfredPros Місяць тому +3

    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()

  • @MikPosp
    @MikPosp Місяць тому +1

    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)

  • @Nikhil-zv3uc
    @Nikhil-zv3uc Місяць тому +14

    "Perhaps you are making a scale to weigh your mom""
    I had to use a different solution because of this....

  • @_PranavDesai
    @_PranavDesai Місяць тому +5

    extra challenge: if you're using python, do it in one line

  • @business_central
    @business_central Місяць тому +3

    Neetcode is pretty chill...... with random spurs of Mom jokes xD 🤣🤣

  • @zanies6288
    @zanies6288 Місяць тому

    Loop through 0 to 31 and Just check if (1

  • @meemee417
    @meemee417 Місяць тому +6

    diabolical use case of 1000 bit number ☠

  • @harsh3305
    @harsh3305 Місяць тому +6

    meanwhile I made functions to convert an int to binary, then pad zeros to the smaller number, then compare each character 😭

    • @Nirjhar_Neer
      @Nirjhar_Neer Місяць тому +2

      us :v

    • @sabukuna
      @sabukuna Місяць тому +2

      same. but its fine. fuck bit manipulation

  • @kushagrasaxena5202
    @kushagrasaxena5202 Місяць тому +4

    The mom joke caught me offguard

  • @chrischika7026
    @chrischika7026 Місяць тому +1

    AND1

  • @b1gfreakn678
    @b1gfreakn678 Місяць тому

    "perhaps you're trying to build a scale to weigh your mom" hahahahahhaahaha

  • @ruslan2676
    @ruslan2676 Місяць тому

    is it just me or video is speeded up a little?

  • @Sharky-1507
    @Sharky-1507 Місяць тому +2

    First!

  • @pastori2672
    @pastori2672 Місяць тому

    honestly the bitwise & with 1 and then bit shift is much more intruitive and readable then the last solution