Skip to content

Commit 6bb93f6

Browse files
authored
Merge pull request neetcode-gh#1785 from AP-Repositories/patch-51
Create 0263-ugly-number.cpp
2 parents 2d69641 + 71c473c commit 6bb93f6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cpp/0263-ugly-number.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
bool isUgly(int n) {
4+
if(n <= 0)
5+
return false;
6+
7+
for(int p: {2, 3, 5})
8+
while(n % p == 0)
9+
n = n / p;
10+
return n == 1;
11+
}
12+
};

0 commit comments

Comments
 (0)