본문 바로가기
LeetCode/2020 LeetCoding Challenge

LeetCode. Power of Two

by 벤진[Benzene] 2020. 6. 9.

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]

댓글