Skip to content

Commit 79651bf

Browse files
authored
Update Ugly number.cpp
Leetcode solution to problem Ugly Number
1 parent 0bffe72 commit 79651bf

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Ugly number.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
1+
/*The ugly number is a positive integer
2+
whose prime factors are limited to 2,3,5.
3+
Given a integer neturn true if n is
4+
ugly number*/
5+
class Solution {
6+
public:
7+
bool isUgly(int n) {
8+
if(n<=0) return false;
9+
while(n%2==0) {
10+
n/=2;
11+
}
12+
while(n%3==0) {
13+
n/=3;
14+
}
15+
while(n%5==0) {
16+
n/=5;
17+
}
18+
return n==1;
19+
}
20+
};

0 commit comments

Comments
 (0)