Leet Code OJ 231. Power of Two [Difficulty: Easy]
生活随笔
收集整理的这篇文章主要介绍了
Leet Code OJ 231. Power of Two [Difficulty: Easy]
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目:
Given an integer, write a function to determine if it is a power of two.
分析:
题意是给定一个整数,判断它是不是2的幂。
代码实现:
public class Solution {public boolean isPowerOfTwo(int n) {if(n<1){return false;}if(n==1){return true;}if((n&1)==0) {return isPowerOfTwo(n/2);} else{return false;}} }总结
以上是生活随笔为你收集整理的Leet Code OJ 231. Power of Two [Difficulty: Easy]的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Leet Code OJ 242. Va
- 下一篇: Leet Code OJ 258. Ad