same code with diffrent result (python, c++)


  • 0
    S

    confused

    python code

    def isUgly(self, num):
            if num <= 0:
            	return False
            while num & 1 == 0:
            	num >>= 1
            while num % 3 == 0:
                num /= 3
            while num % 5 == 0:
            	num /= 5
            return num == 1
    

    C++ code

    bool isUgly(int num) {
        if (num <= 0)
            return false;
        while (num & 1 == 0)  // Accepted if use  (num % 2 == 0) here
            num >>= 1;
        while (num % 3 == 0)
            num /= 3;
        while (num % 5 == 0)
            num /= 5;
        return num == 1;
    }
    

Log in to reply
 

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