-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path263.丑数.py
More file actions
59 lines (58 loc) · 1.09 KB
/
263.丑数.py
File metadata and controls
59 lines (58 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# @lc app=leetcode.cn id=263 lang=python
#
# [263] 丑数
#
# https://leetcode-cn.com/problems/ugly-number/description/
#
# algorithms
# Easy (47.61%)
# Likes: 74
# Dislikes: 0
# Total Accepted: 16.2K
# Total Submissions: 34K
# Testcase Example: '6'
#
# 编写一个程序判断给定的数是否为丑数。
#
# 丑数就是只包含质因数 2, 3, 5 的正整数。
#
# 示例 1:
#
# 输入: 6
# 输出: true
# 解释: 6 = 2 × 3
#
# 示例 2:
#
# 输入: 8
# 输出: true
# 解释: 8 = 2 × 2 × 2
#
#
# 示例 3:
#
# 输入: 14
# 输出: false
# 解释: 14 不是丑数,因为它包含了另外一个质因数 7。
#
# 说明:
#
#
# 1 是丑数。
# 输入不会超过 32 位有符号整数的范围: [−2^31, 2^31 − 1]。
#
#
#
class Solution(object):
def isUgly(self, num):
"""
:type num: int
:rtype: bool
"""
if num==0:return False
if num==1:return True
if num%2==0:return self.isUgly(num/2)
if num%3==0:return self.isUgly(num/3)
if num%5==0:return self.isUgly(num/5)
return False