Skip to content

Commit aa49991

Browse files
committed
Added Python solution for "Ugly Number"
1 parent be8389a commit aa49991

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Python/Ugly Number.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
"""
3+
Time: O(log(n))
4+
Memory: O(1)
5+
"""
6+
7+
def isUgly(self, n: int) -> bool:
8+
while n > 1:
9+
if not n % 5:
10+
n //= 5
11+
elif not n % 3:
12+
n //= 3
13+
elif not n % 2:
14+
n //= 2
15+
else:
16+
return False
17+
18+
return n > 0
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)