a unique solution


  • 0
    P

    '''
    bool isUgly(int n) {
    if (n<0) return false;
    while (n % 15 == 0)
    n /= 15;
    while (n % 10 == 0)
    n /= 10;
    while (n % 6 == 0)
    n /= 6;
    if ((n&(n - 1)) == 0 || 1162261467 % n == 0 || 1220703125 % n == 0)
    return true;
    else return false;
    }
    '''


  • 0
    C

    Interesting.
    Should faster than loop 2/3/5.
    But. the 2nd line should be: n<1 return false;
    otherwise "n=0" will cause problem in 1162261467 % n


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.