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
- list
- 오픈 채팅방
- leetcode
- 리스트
- kakao
- LinkedList
- 완전검색
- sorting
- binary search tree
- 카카오
- traversal
- tree
- 트리
- 공채
- 스택
- 순회
- 2019 카카오
- 정렬
- bst
- Linked List
- Bit
- Subset
- Easy
- Math
- Bubble Sort
- stack
- Medium
- 배열
Archives
- Today
- Total
미리수얌 블로그
Leetcode: Power of Four 본문
Power of Four
자 저번에 본 Power of Two 를 응용해서 Power of Four 도 풀어보겠습니다.
4 의 거듭제곱들을 보죠
4
16
64
256
보면 1의 자리가 4 6 4 6 으로 패턴이 있음을 알 수 있습니다.
그렇다면 2 의 거듭제곱에다가 일의 자리가 4 나 6으로 끝나면
4의 거듭제곱입니다.
public boolean isPowerOfFour(int num) {
// power of 2
int one = num % 10;
return (num == 1) || (((num & (num - 1)) == 0) && (one == 4 || one == 6));
}
'코딩문제풀이 > Leetcode' 카테고리의 다른 글
Leetcode: Minimum Time Difference (0) | 2018.10.17 |
---|---|
Leetcode: Power of Two (0) | 2018.10.05 |
Leetcode: Set Mismatch (0) | 2018.10.05 |
Leetcode: Diameter of Binary Tree (0) | 2018.09.29 |
Leetcode: String Compression (0) | 2018.09.29 |
Comments