[Python]OJ's result is different with mine... why?


  • 0
    K

    My Codes are in below:

    class Solution(object):
    def isPowerOfFour(self, num):
        """
        :type num: int
        :rtype: bool
        """
        print("\n",num)
        if num <= 0:
            return False
        if num in (1,4):
            return True
            
        if num / 4 % 4 <= 0:
            return True
        else:
            return False
    

    The Results in OJ with input of 17,16,5,4,3,2,1,0 are

    [T] [T] [F] [T] [F] [F] [T] [F]

    .
    Then I tested my code in my labtop with these codes:

    if __name__ == "__main__":
    s = Solution()
    print(s.isPowerOfFour(17))
    print(s.isPowerOfFour(16))
    print(s.isPowerOfFour(5))
    print(s.isPowerOfFour(4))
    print(s.isPowerOfFour(3))
    print(s.isPowerOfFour(2))
    print(s.isPowerOfFour(1))
    print(s.isPowerOfFour(0))
    

    My Results are

    [F] [T] [F] [T] [F] [F] [T] [F]

    (The right answer)...

    This make me confused...
    Why?


  • 0
    K

    By the way...
    Along the description of this question... We just need to check whether the integer num is power of 4.
    I noticed that the number 2 is an integer which also is 1/2 power of 4...So the answer may should be true?


Log in to reply
 

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