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 | 31 |
Tags
- implement
- Counting
- Binary Tree
- Class
- Tree
- 코딩테스트
- geometry
- java
- array
- 파이썬
- Method
- string
- Matrix
- Binary Search
- hash table
- sorting
- greedy
- database
- simulation
- 코테
- Data Structure
- two pointers
- 자바
- Stack
- dynamic programming
- SQL
- Math
- Number Theory
- bit manipulation
- 구현
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 231. Power of Two 본문
1. Input
1) 정수 n
2. Output
1) n이 2의 거듭제곱이면 true 반환
2) 아니라면 false 반환
3. Constraint
1) - 2^31 <= n <= 2^31 - 1
4. Example
Input: n=16 -> Output: true (16 = 2^4)
Input: n=33 -> Output: false
5. Code
1) 첫 코드(2022/07/19)
if(n==1)
return true;
if(n<=0)
return false;
double num = n;
while(num>=2)
num /= 2;
if(num==1)
return true;
else
return false;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 258. Add Digits (0) | 2022.10.14 |
---|---|
[LeetCode/Easy] 242. Valid Anagram (0) | 2022.10.13 |
[LeetCode/Easy] 217. Contains Duplicate (0) | 2022.10.12 |
[LeetCode/Easy] 191. Number of 1 Bits (0) | 2022.10.12 |
[LeetCode/Easy] 190. Reverse Bits (0) | 2022.10.12 |