Ugly Number - Leetcode 263 - Python

preview_player
Показать описание


0:00 - Read the problem
1:40 - Drawing Explanation
8:44 - Coding Explanation

leetcode 263

#prime #number #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.
Рекомендации по теме
Комментарии
Автор

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

youngee
Автор

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

littlecatboybuddy
Автор

My Favorite YT chanel, don't ask me why

jideabdqudus
Автор

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

harshaggarwal
Автор

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

Punibaba
Автор

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

swatiaga
Автор

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

Gerald-izmv
Автор

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;

amalaljohari
Автор

it should be "if n <= 1: return False" to account for "1", since it is NOT an ugly number.

pbergn
Автор

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<=1 return false? Or am i mistaking something

duckieace
Автор

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

monkeyDluffy-sdzp
Автор

i think u r from mars ur every video is educative

Rishabhsingh-evii
Автор

but the test case says 20 is an ugly number.

monkeyDluffy-sdzp
Автор

But anyways thanks for good explanation

TachAtayeva
join shbcf.ru