Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- hackerrank
- Docker
- Git
- 백준
- PYTHON
- Kaggle
- gs25
- 프로그래머스 파이썬
- leetcode
- 우분투
- ubuntu
- 맥북
- programmers
- SW Expert Academy
- Real or Not? NLP with Disaster Tweets
- github
- 편스토랑 우승상품
- 금융문자분석경진대회
- AI 경진대회
- 파이썬
- ChatGPT
- 프로그래머스
- 코로나19
- 데이콘
- dacon
- 더현대서울 맛집
- 캐치카페
- 편스토랑
- 자연어처리
- Baekjoon
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 231. Power of Two (Python) 본문
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
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
| [leetCode] 371. Sum of Two Integers (Python) (0) | 2020.07.14 |
|---|---|
| [leetCode] 1. Two Sum (Python) (0) | 2020.07.13 |
| [leetCode] 989. Add to Array-Form of Integer (Python) (0) | 2020.07.11 |
| [HackerRank] Day 14: Scope (Python) (0) | 2020.07.10 |
| [leetCode] 198. House Robber (Python) (0) | 2020.07.09 |
Comments