Skip to content

Commit 06fcdb0

Browse files
committed
Add ugly number answer
1 parent e78a5b6 commit 06fcdb0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: ugly-number.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func isUgly(num int) bool {
8+
if num == 0 {
9+
return false
10+
}
11+
if num == 1 {
12+
return true
13+
}
14+
for num%2 == 0 {
15+
num /= 2
16+
}
17+
for num%3 == 0 {
18+
num /= 3
19+
}
20+
for num%5 == 0 {
21+
num /= 5
22+
}
23+
return num == 1
24+
}
25+
26+
func main() {
27+
fmt.Println(isUgly(-2147483648))
28+
}

0 commit comments

Comments
 (0)