LeetCode 263 Ugly Number
很多人出现Time Limit Exceeded的情况,是由于没有判断num是否等于0.
bool isUgly(int num) { if(num==0) return false; while(num%2 == 0) num/=2; while(num%3 == 0) num/=3; while(num%5 == 0) num/=5; return num==1; }
LeetCode 263 Ugly Number
很多人出现Time Limit Exceeded的情况,是由于没有判断num是否等于0.
bool isUgly(int num) { if(num==0) return false; while(num%2 == 0) num/=2; while(num%3 == 0) num/=3; while(num%5 == 0) num/=5; return num==1; }