您的位置:首页 > 其它

[leetcode]231. Power of Two

2016-03-18 17:01 239 查看

231. Power of Two



Total Accepted: 62182 Total Submissions: 173791 Difficulty: Easy

Given an integer, write a function to determine if it is a power of two.

Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

class Solution {
public:
bool isPowerOfTwo(int n) {

return (n>0)&&((n&(n-1))==0);
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: