Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 263. Ugly Number
- Runtime: 32 ms, faster than 95.67% of Python3 online submissions for Ugly Number.
- Memory Usage: 14.1 MB, less than 6.67% of Python3 online submissions for Ugly Number.
- """
- class Solution:
- def isUgly(self, num):
- # int -> bool
- if num <= 0: return False
- for p in (30, 10, 5, 3, 2):
- while num % p == 0:
- num = num / p
- return num == 1
- class Solution:
- def isUgly(self, num):
- # int -> bool
- if num <= 0:
- return False
- while (num % 2 == 0):
- num = num / 2
- while (num % 3 == 0):
- num = num / 3
- while (num % 5 == 0):
- num = num / 5
- if num == 1:
- return True
- else:
- return False
- print(Solution().isUgly(0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement