Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- github
- 그리디
- golang
- Backjoon
- go
- 알고리즘
- 피보나치
- GCP
- Python
- BubbleSort
- cpu scheduling
- Dynamic Programming
- docker
- kubernetes
- Observer Pattern
- 백준
- LeetCode
- java
- Singleton Pattern
- Kotlin
- 파이썬
- k8s
- GKE
- Codility
- Top-down
- Programmers
- easy
- mobaXTerm
- KAKAO
Archives
- Today
- Total
To Be Developer
[LeetCode] 231. Power of Two 본문
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
'''
문제설명
n 이 2의 거듭제곱이면 True,
그렇지 않으면 False를 Return 하라.
'''
# 반복문이 몇 번 돌았는지 체크해주는
# count 변수
cnt = 0
while True:
# 만약 2 ** cnt 가 n 이면 거듭제곱
# Return True
if 2 ** cnt == n:
return True
# 만약 거듭제곱이 n 보다 크면
# 반복할 필요 없으니
if 2 ** cnt > n :
return False
# cnt 를 1 증가 시킴
cnt += 1
return False
if __name__ == "__main__":
input = 1
sl = Solution().isPowerOfTwo(input)
print(sl)
'알고리즘 > LeetCode' 카테고리의 다른 글
| [LeetCode] 217. Contains Duplicate (0) | 2019.03.20 |
|---|---|
| [LeetCode] Reverse Words in a String (0) | 2019.03.19 |
| [LeetCode] 225. Implement Stack using Queues (0) | 2019.03.13 |
| [LeetCode] 189. Rotate Array.py (0) | 2019.03.08 |
| [LeetCode] 7. Reverse Integer (0) | 2019.03.06 |