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
- greedy
- 구현
- Binary Search
- simulation
- Math
- bit manipulation
- Data Structure
- java
- string
- Stack
- dynamic programming
- Binary Tree
- array
- 코딩테스트
- Counting
- 자바
- Method
- Matrix
- geometry
- Number Theory
- 파이썬
- two pointers
- 코테
- database
- implement
- sorting
- hash table
- Class
- Tree
- SQL
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 |