Leetcode - Coin Change 2
Leetcode - Power of Three

Leetcode - Power of Two

violet posted @ Jun 09, 2020 12:36:12 AM in 算法 with tags Algorithm Golang math , 232 阅读

https://leetcode.com/problems/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: 20 = 1

Example 2:

Input: 16
Output: true
Explanation: 24 = 16

 

func isPowerOfTwo(n int) bool {
    return n > 0 && 1073741824 % n == 0
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter