My javascript solution


  • 0
    T
    /**
     * @param {number} num
     * @return {boolean}
     */
    var isUgly = function(num) {
        if(num === 0) {
            return false;
        }
        
        while(true) {
            if(num % 2 === 0) {
                num /= 2;
            } else if(num % 3 === 0) {
                num /= 3;
            } else if(num % 5 === 0) {
                num /= 5
            } else if(num === 1) {
                return true;
            } else {
                return false;
            }
        }
    };

Log in to reply
 

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