File tree 3 files changed +66
-0
lines changed
3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 16
16
| [ 11] ( ./algorithms/0011 ) | [ 11. 盛最多水的容器] ( https://leetcode-cn.com/problems/container-with-most-water/ ) | [ Go] ( ./algorithms/0011/main.go ) | 中等 |
17
17
| [ 14] ( ./algorithms/0014 ) | [ 14. 最长公共前缀] ( https://leetcode-cn.com/problems/longest-common-prefix/ ) | [ Go] ( ./algorithms/0014/main.go ) | 简单 |
18
18
| [ 79] ( ./algorithms/0079 ) | [ 79. 单词搜索] ( https://leetcode-cn.com/problems/word-search/ ) | [ Go] ( ./algorithms/0079/main.go ) | 中等 |
19
+ | [ 263] ( ./algorithms/0263 ) | [ 263. 丑数] ( https://leetcode-cn.com/problems/ugly-number/ ) | [ Go] ( ./algorithms/0263/main.go ) | 简单 |
19
20
| [ offer47] ( ./algorithms/offer47 ) | [ 剑指 Offer 47. 礼物的最大价值] ( https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/ ) | [ Go] ( ./algorithms/offer47/main.go ) | 中等 |
20
21
21
22
Original file line number Diff line number Diff line change
1
+ #### [ 263. 丑数] ( https://leetcode-cn.com/problems/ugly-number/ )
2
+
3
+ 难度简单
4
+
5
+ 给你一个整数 ` n ` ,请你判断 ` n ` 是否为 ** 丑数** 。如果是,返回 ` true ` ;否则,返回 ` false ` 。
6
+
7
+ ** 丑数** 就是只包含质因数 ` 2 ` 、` 3 ` 和/或 ` 5 ` 的正整数。
8
+
9
+
10
+
11
+ ** 示例 1:**
12
+
13
+ ```
14
+ 输入:n = 6
15
+ 输出:true
16
+ 解释:6 = 2 × 3
17
+ ```
18
+
19
+ ** 示例 2:**
20
+
21
+ ```
22
+ 输入:n = 8
23
+ 输出:true
24
+ 解释:8 = 2 × 2 × 2
25
+ ```
26
+
27
+ ** 示例 3:**
28
+
29
+ ```
30
+ 输入:n = 14
31
+ 输出:false
32
+ 解释:14 不是丑数,因为它包含了另外一个质因数 7 。
33
+ ```
34
+
35
+ ** 示例 4:**
36
+
37
+ ```
38
+ 输入:n = 1
39
+ 输出:true
40
+ 解释:1 通常被视为丑数。
41
+ ```
42
+
43
+
44
+
45
+ ** 提示:**
46
+
47
+ - ` -231 <= n <= 231 - 1 `
Original file line number Diff line number Diff line change
1
+ package _0263
2
+
3
+ func isUgly (n int ) bool {
4
+ if n <= 0 {
5
+ return false
6
+ }
7
+ if n == 1 {
8
+ return true
9
+ }
10
+ if n % 2 == 0 {
11
+ return isUgly (n / 2 )
12
+ } else if n % 3 == 0 {
13
+ return isUgly (n / 3 )
14
+ } else if n % 5 == 0 {
15
+ return isUgly (n / 5 )
16
+ }
17
+ return false
18
+ }
You can’t perform that action at this time.
0 commit comments