관리 메뉴

솜씨좋은장씨

[leetCode] 231. Power of Two (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 231. Power of Two (Python)

솜씨좋은장씨 2020. 7. 12. 00:38
728x90
반응형

Given an integer, write a function to determine if it is a power of two.

 

Example 1:

Input: 1
Output: true 
Explanation: 20 = 1

Example 2:

Input: 16
Output: true
Explanation: 24 = 16

Example 3:

Input: 218
Output: false

Solution

class Solution:
    def isPowerOfTwo(self, n: int) -> bool:
        answer = False
        pow_2s = []
        
        for i in range(50):
            pow_2s.append(pow(2, i))
            
        if n in pow_2s:
            answer = True
            
        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