File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * @lc app=leetcode id=231 lang=java
3
+ *
4
+ * [231] Power of Two
5
+ *
6
+ * https://leetcode.com/problems/power-of-two/description/
7
+ *
8
+ * algorithms
9
+ * Easy (41.58%)
10
+ * Total Accepted: 211.8K
11
+ * Total Submissions: 509.3K
12
+ * Testcase Example: '1'
13
+ *
14
+ * Given an integer, write a function to determine if it is a power of two.
15
+ *
16
+ * Example 1:
17
+ *
18
+ *
19
+ * Input: 1
20
+ * Output: true
21
+ * Explanation: 20 = 1
22
+ *
23
+ *
24
+ * Example 2:
25
+ *
26
+ *
27
+ * Input: 16
28
+ * Output: true
29
+ * Explanation: 24 = 16
30
+ *
31
+ * Example 3:
32
+ *
33
+ *
34
+ * Input: 218
35
+ * Output: false
36
+ *
37
+ */
38
+ class Solution {
39
+ public boolean isPowerOfTwo (int n ) {
40
+ if (n <= 0 ) return false ;
41
+ if ((n & (n -1 )) == 0 ) {
42
+ return true ;
43
+ }
44
+ return false ;
45
+ }
46
+ }
47
+
You can’t perform that action at this time.
0 commit comments