Skip to content

Commit 45e845f

Browse files
authored
Merge pull request #1 from anelatrakic/anelatrakic-contribution
Adding a second solution to Ugly-Number.java
2 parents 80c004e + c77dc5d commit 45e845f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Java/Ugly-Number.java

+16
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ public boolean isUgly(int num) {
2121
return false;
2222
}
2323
}
24+
25+
/* adding another solution without recursion */
26+
class Solution {
27+
public boolean isUgly(int num) {
28+
if (num <= 0) return false;
29+
int[] divisors = {2, 3, 5};
30+
31+
for (int divisor : divisors) {
32+
while (num % divisor == 0) {
33+
num /= divisor;
34+
}
35+
}
36+
37+
return num == 1;
38+
}
39+
}

0 commit comments

Comments
 (0)