Ugly Number - Leetcode 263 - Python

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

КОМЕНТАРІ • 32

  • @youngee9403
    @youngee9403 3 роки тому +57

    there are times that i wonder if im being punished for skipping all my math classes during undergrad

    • @NeetCode
      @NeetCode  3 роки тому +7

      I feel the same sometimes lol

    • @KarthikKumaresan-k1o
      @KarthikKumaresan-k1o 4 місяці тому

      There are times I wonder if I am being punished for not studying Computer Science Major but trying to be a software programmer.. lol

  • @jideabdqudus
    @jideabdqudus 3 роки тому +9

    My Favorite YT chanel, don't ask me why

  • @swatiaga8554
    @swatiaga8554 2 роки тому +3

    you can also add one more condition at while loop that n!= 0 otherwise the loop will be infinite.

  • @harshaggarwal1967
    @harshaggarwal1967 2 роки тому +6

    You just made it quick and easy.. Thanks!!

  • @sudluee
    @sudluee 3 роки тому +6

    i think the worse case time complexity is O(log(2)n) that's if n is only divisible by 2.

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

      I think the time complexity could be O(1).

  • @littlecatboybuddy
    @littlecatboybuddy Рік тому

    I watch entire videos! Because I'm a beginner so the coding section is really helpful! Thank you for the great explanation :)

  • @fsteve6443
    @fsteve6443 3 роки тому +11

    the GOAT uploaded

    • @BB8_CA
      @BB8_CA 3 роки тому

      As aways!

  • @Gerald-iz7mv
    @Gerald-iz7mv Рік тому

    hi - is there a leetcode playlist for this as well?

  • @amalaljohari9358
    @amalaljohari9358 Рік тому +2

    Actually that shows "Time Limit Exceeded"
    A better solution can be:
    if (n < 0)
    return false;
    while (n > 1)
    {
    if (n % 2 == 0) n /= 2;
    else if (n % 3 == 0) n /= 3;
    else if (n % 5 == 0) n /= 5;
    else return false;
    }
    return n ==1;

    • @NegiRohit
      @NegiRohit Рік тому

      I came up with this exact solution without seeing this code.

  • @mythologyKnowledge6581
    @mythologyKnowledge6581 15 днів тому

    Great explanation

  • @duckieace
    @duckieace 2 роки тому +2

    What happens if n is 1. This code seems like it return it as True even though the prime number of 1 is not 2 3 or 5. shouldn't it be if n

    • @spaceface2288
      @spaceface2288 2 роки тому

      if n == 0: return False
      while n % 2 == 0:
      n = n / 2
      while n % 3 == 0:
      n = n / 3
      while n % 5 == 0:
      n = n / 5

      return n == 1

    • @sahanar4805
      @sahanar4805 2 роки тому

      +1

    • @harshaggarwal1967
      @harshaggarwal1967 2 роки тому +1

      1 has no prime factors, therefore all of its prime factors are limited to 2,3 and 5..so we can take it as ugly number..
      Hence return true for this case..

  • @monkeyDluffy-sd3zp
    @monkeyDluffy-sd3zp Рік тому +1

    20 is not considered an ugly number. An ugly number must only be divisible by 2, 3, or 5, but 20 is also divisible by 4, which is not among the allowed prime factors. -source chatgpt

    • @user-qg7lb1jx8b
      @user-qg7lb1jx8b Рік тому +4

      4 is not prime

    • @ChrisCox-wv7oo
      @ChrisCox-wv7oo Рік тому +2

      Being divisible by 4 is the same as being divisible by 2 two times...
      I'm not sure if Chad GPT is going to do mentally cripple an entire generation of engineers, or help them learn quicker through failure

  • @Rishabhsingh-ev7ii
    @Rishabhsingh-ev7ii 2 роки тому

    i think u r from mars ur every video is educative

  • @maamounhajnajeeb209
    @maamounhajnajeeb209 Рік тому

    Thanks

  • @monkeyDluffy-sd3zp
    @monkeyDluffy-sd3zp Рік тому +1

    but the test case says 20 is an ugly number.

  • @_tan2112
    @_tan2112 Рік тому

    Helpfull

  • @gersonsales9231
    @gersonsales9231 2 роки тому

    ++subscribers