관리 메뉴

솜씨좋은장씨

[leetCode] 342. Power of Four (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 342. Power of Four (Python)

솜씨좋은장씨 2020. 7. 24. 00:16
728x90
반응형

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

 

Example 1:

Input: 16
Output: true

Example 2:

Input: 5
Output: false

Follow up: Could you solve it without loops/recursion?

Accepted

 

Solution

class Solution:
    def isPowerOfFour(self, num: int) -> bool:
        if num <= 0: 
            answer =False
        else:
            while num % 4 == 0:
                num = num / 4
            if num == 1:
                answer = True
            else:
                answer = False
        return answer

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

Comments