-
Notifications
You must be signed in to change notification settings - Fork 0
263_UglyNumber
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
bool isUgly(int n) {
if(n<1) return false;
while(n%2==0) n>>=1;
while(n%3==0) n/=3;
while(n%5==0) n/=5;
return n==1;
}
};
- time complexity
O(logn)
- space complexity
O(1)
footer