public class Solution {
public boolean isUgly(int num) {
if(num == 1)
return true;
if(num == 0)
return false;
if(num%2 == 0)
return isUgly(num/2);
if(num%3 == 0)
return isUgly(num/3);
if(num%5 == 0)
return isUgly(num/5);
return false;
}
}
public boolean isUgly(int num) {
if(num==1) return true;
if(num==0) return false;
while(num%2==0) num=num>>1;
while(num%3==0) num=num/3;
while(num%5==0) num=num/5;
return num==1;
}
简单的说能用循环去解决的尽量去避免是用递归会好一些
num%2==0确实还可以写成n&1==0,但是为了可读性不做修改