Problem:
Given an integer, write a function to determine if it is a power of two.
Example 1:
Input: 1
Output: true
Explanation: 20 = 1
Example 2:
Input: 16
Output: true
Explanation: 24 = 16
Example 3:
Input: 218
Output: false
-Summary-
1. Keep divide number by 2. In the iteration, if any number divide by 2 is not 0, then return False
2. After the loop, return True since the number is a power of two.
모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]
'LeetCode > 2020 LeetCoding Challenge' 카테고리의 다른 글
LeetCode. Largest Divisible Subset (0) | 2020.06.14 |
---|---|
LeetCode. Insert Delete GetRandom O(1) (0) | 2020.06.13 |
LeetCode. Sort Colors (0) | 2020.06.12 |
LeetCode. Search Insert Position [Binary Search] (0) | 2020.06.11 |
LeetCode. Is Subsequence (0) | 2020.06.10 |
댓글