欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Leet Code OJ 231. Power of Two [Difficulty: Easy]

发布时间:2024/2/28 编程问答 36 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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]的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。