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