Skip to content

Commit f38b821

Browse files
refactor 263
1 parent c72674b commit f38b821

File tree

1 file changed

+11
-15
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+11
-15
lines changed
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
package com.fishercoder.solutions;
22

3-
/**Write a program to check whether a given number is an ugly number.
4-
5-
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
6-
7-
Note that 1 is typically treated as an ugly number.*/
8-
93
public class _263 {
104

11-
public boolean isUgly(int num) {
12-
if (num == 0) {
13-
return false;
14-
}
15-
int[] divisors = new int[]{5, 3, 2};
16-
for (int divisor : divisors) {
17-
while (num % divisor == 0) {
18-
num /= divisor;
5+
public static class Solution1 {
6+
public boolean isUgly(int num) {
7+
if (num == 0) {
8+
return false;
9+
}
10+
int[] divisors = new int[]{5, 3, 2};
11+
for (int divisor : divisors) {
12+
while (num % divisor == 0) {
13+
num /= divisor;
14+
}
1915
}
16+
return num == 1;
2017
}
21-
return num == 1;
2218
}
2319

2420
}

0 commit comments

Comments
 (0)