Posted on 2022-11-18 16:55
Uriel 閱讀(52)
評論(0) 編輯 收藏 引用 所屬分類:
閑來無事重切Leet Code 、
大水題
判斷一個數的因數是否只有2,3,5,大水題
1 #263
2 #Runtime: 31 ms
3 #Memory Usage: 13.4 MB
4
5 class Solution(object):
6 def isUgly(self, n):
7 """
8 :type n: int
9 :rtype: bool
10 """
11 while n > 1 and (n % 2) == 0:
12 n /= 2
13 while n > 1 and (n % 3) == 0:
14 n /= 3
15 while n > 1 and (n % 5) == 0:
16 n /= 5
17 if n == 1:
18 return True
19 return False