231. Power of Two (判断一个数是否是2的幂)
Given an integer, write a function to determine if it is a power of two.
public class Solution {
public boolean isPowerOfTwo(int n) {
return n>0&&Integer.bitCount(n)==1;//Integer.bitCount(-2147483648) is 1
}
}
Given an integer, write a function to determine if it is a power of two.
public class Solution {
public boolean isPowerOfTwo(int n) {
return n>0&&Integer.bitCount(n)==1;//Integer.bitCount(-2147483648) is 1
}
}
Given an integer, write a function to determine if it is a power of two. Example 1:
题目描述: 给定一个整数,编写一个函数来判断它是否是 2 的幂次方。 示例 1: 输入: 1 输出: true 解释: 20 = 1 示例 2: 输入: 1
位运算 public class Solution { public boolean isPowerOfTwo(int n) {
Given an integer, write a function to determine if it is a power of three. Follow up:
Given an integer, write a function to determine if it is a power of two. public cla
Given an integer, write a function to determine if it is a power of two. public cla
1.题目 Given an integer, write a function to determine if it is a power of two. 判断一个整
/\ Given an integer, write a function to determine if it is a power of two. \/
Given an integer, write a function to determine if it is a power of two. 就是判断一个数是不是2的次方
Given an integer, write a function to determine if it is a power of two. Example 1:
还没有评论,来说两句吧...