Title Description ：

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

Their thinking ：

The judgment method is mainly based on 2 Of N The characteristics of power ： Only the first is 1, The rest of you are for 0.

The code is as follows ：

public class Solution {

public boolean isPowerOfTwo(int n) {

return (n > 0) && ( n & (n - 1)) == 0;

}

}

## Java [Leetcode 231]Power of Two More articles about

- [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four
All three topics have the same meaning , Is to determine whether a number is 2/3/4 The power of , There are general methods in these questions , There are different ways , I'll talk about it separately . Original address :231 Power of Two:https://leetcode. ...

- [LeetCode] 231. Power of Two 2 The number of squares
Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: ...

- LN : leetcode 231 Power of Two
lc 231 Power of Two 231 Power of Two Given an integer, write a function to determine if it is a powe ...

- Java for LeetCode 231 Power of Two
public boolean isPowerOfTwo(int n) { if(n<1) return false; while(n!=1){ if(n%2!=0) return false; ...

- LeetCode 231 Power of Two
Problem: Given an integer, write a function to determine if it is a power of two. Summary: Judge a number n Is it right? ...

- Leetcode 231 Power of Two number theory
The same is to judge whether the number is 2 Of n The next power , Same as Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...

- (easy)LeetCode 231.Power of Two
Given an integer, write a function to determine if it is a power of two. Credits:Special thanks to @ ...

- Java [Leetcode 326]Power of Three
Title Description : Given an integer, write a function to determine if it is a power of three. Follow up:Could you ...

- [LeetCode] 231. Power of Two *( whether 2 The power of )
describe 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 2 Of ...

## Random recommendation

- Activity Boot mode
------siwuxie095 common 4 Start mode :standard singleTop singleTask singleInstance 1. Standard start mode (standard) The default startup mode ( ...

- Leetcode 231 Power of Two number theory
The same is to judge whether the number is 2 Of n The next power , Same as Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...

- 【 Important version 】Firefly alpha beta v1.2.2 Official release
The original address :http://bbs.gameres.com/thread_220175.html firefly 1.2.2 to update Update the content : Function add 1. Dynamic module update 2. part b ...

- solve Ubuntu 14.04 Next SMPlayer The problem of subtitle garbled
1.SMPlayer player For the use of ubuntu Students of the system , Although the system started with vedio player , But it's highly recommended SMPlayer, Directly in Ubuntu Software Center You can download and install it for free ...

- c++ Parameter passing
Definition : Formal parameter : Point out that today Sub and Function The variable name in the procedure parameter list . Array name , The procedure is called before . No memory is allocated for them . Its function is to explain the type and form of the independent variable and its role in the process . A formal parameter can be a combination other than a fixed length string variable ...

- GoodReads: Machine Learning (Part 3)
In the first installment of this series, we scraped reviews from Goodreads. In thesecond one, we per ...

- Go The deep practice of Zhongyuan
1. Introduce 2. Transport layer socket 2.1 ICMP 2.2 TCP 2.3 Transport layer protocol 3. The network layer socket 3.1 Use Go library 3.2 system call 3.3 Network layer protocol 4. summary 4.1 Reference resources ...

- Initialize the repository （git init）
Create a new warehouse First, enter the directory that needs to be initialized , Then input git init D:\Git\test λ git init Initialized empty Git repository in D:/Git/t ...

- nodejs( 5、 ... and ) Synchronous asynchronous --BLOCKING THE EVENT LOOP
1.BLOCKING THE EVENT LOOP Node and JavaScript runtimes in general are single-threaded event loops. O ...

- QWebEngineView_CssVariables
1. Test code , Refer to the website :http://blog.sina.com.cn/s/blog_1508519340102wgq0.html 2. Test it out , result : 2.1.Qt5.6 Start , No, WebKit 了 . ...