SHARE
TWEET

Untitled

a guest Sep 16th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. 263. Ugly Number
  3. Runtime: 32 ms, faster than 95.67% of Python3 online submissions for Ugly Number.
  4. Memory Usage: 14.1 MB, less than 6.67% of Python3 online submissions for Ugly Number.
  5. """
  6.  
  7. class Solution:
  8.     def isUgly(self, num):
  9.         # int -> bool
  10.         if num <= 0: return False
  11.         for p in (30, 10, 5, 3, 2):
  12.             while num % p == 0:
  13.                 num = num / p
  14.         return num == 1
  15.  
  16. class Solution:
  17.     def isUgly(self, num):
  18.         # int -> bool
  19.         if num <= 0:
  20.             return False
  21.         while (num % 2 == 0):
  22.             num = num / 2
  23.         while (num % 3 == 0):
  24.             num = num / 3
  25.         while (num % 5 == 0):
  26.             num = num / 5
  27.         if num == 1:
  28.             return True
  29.         else:
  30.             return False
  31.  
  32.  
  33. print(Solution().isUgly(0))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top