Skip to content

Commit 476a880

Browse files
committed
ugly_number
1 parent 7dd5716 commit 476a880

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
201201
#### [257. Binary Tree Paths](https://github.com/hitzzc/go-leetcode/tree/master/binary_tree_paths)
202202
#### [258. Add Digits](https://github.com/hitzzc/go-leetcode/tree/master/add_digits)
203203
#### [260. Single Number III](https://github.com/hitzzc/go-leetcode/tree/master/single_number_III)
204+
#### [263. Ugly Number](https://github.com/hitzzc/go-leetcode/tree/master/ugly_number)
204205

205206

206207

ugly_number/ugly_number.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ugly_number
2+
3+
func isUgly(num int) bool {
4+
if num == 0 {
5+
return false
6+
}
7+
for ; num%2 == 0; num /= 2 {
8+
}
9+
for ; num%3 == 0; num /= 3 {
10+
}
11+
for ; num%5 == 0; num /= 5 {
12+
}
13+
if num == 1 {
14+
return true
15+
}
16+
return false
17+
}

0 commit comments

Comments
 (0)