Skip to content

Commit 4b8a16e

Browse files
committed
add 0263
1 parent 0e049af commit 4b8a16e

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
| [11](./algorithms/0011) | [11. 盛最多水的容器](https://leetcode-cn.com/problems/container-with-most-water/) | [Go](./algorithms/0011/main.go) | 中等 |
1717
| [14](./algorithms/0014) | [14. 最长公共前缀](https://leetcode-cn.com/problems/longest-common-prefix/) | [Go](./algorithms/0014/main.go) | 简单 |
1818
| [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) | 简单 |
1920
| [offer47](./algorithms/offer47) | [剑指 Offer 47. 礼物的最大价值](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | [Go](./algorithms/offer47/main.go) | 中等 |
2021

2122

algorithms/0263/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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`

algorithms/0263/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

0 commit comments

Comments
 (0)