Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
231. Power of Two.go
231. Power of Two_test.go

231. Power of Two


Given an integer, write a function to determine if it is a power of two.

Example 1:

Input: 1
Output: true 
Explanation: 2^0 = 1

Example 2:

Input: 16
Output: true
Explanation: 2^4 = 16

Example 3:

Input: 218
Output: false


给定一个整数,编写一个函数来判断它是否是 2 的幂次方。


  • 判断一个数是不是 2 的 n 次方。
  • 这一题最简单的思路是循环,可以通过。但是题目要求不循环就要判断,这就需要用到数论的知识了。这一题和第 326 题是一样的思路。
You can’t perform that action at this time.