일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Clone
- webpack
- leetcode
- Python
- docker
- 앙상블
- machine learning
- bash
- nginx
- security
- scss
- type
- vuetify
- dotenv
- 보안
- loop
- C++
- C#
- VUE
- vue.js
- property
- generic
- TypeScript
- JavaScript
- git
- BOJ
- condition
- AI
- npm
- var
Archives
- Today
- Total
ice rabbit programming
[LeetCode] 231. Power of Two 본문
728x90
leetcode.com/problems/power-of-two/
Power of Two - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
제목 그대로, 입력된 숫자가 2의 제곱수인지를 판별하는 문제이다. 고전적으로 계속 2로 나누는 방식을 선택했는데, 무리없이 해결되었다.
class Solution:
def isPowerOfTwo(self, n: int) -> bool:
if n < 1:
return False
while n > 1:
if n%2 != 0:
return False
n /= 2
return True
728x90
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] 766. toeplitz-matrix (0) | 2022.11.10 |
---|---|
[LeetCode] 242. Valid Anagram (0) | 2022.10.17 |
[LeetCode] 217. Contains Duplocate (0) | 2020.12.08 |
[LeetCode] 191. Numbers of 1 Bits (0) | 2020.12.08 |
[LeetCode] 190. Reverse Bits (0) | 2020.12.08 |