generated from NikiforovAll/leetcode-playground-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path231.power-of-two.cs
53 lines (53 loc) · 866 Bytes
/
231.power-of-two.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* @lc app=leetcode id=231 lang=csharp
*
* [231] Power of Two
*
* https://leetcode.com/problems/power-of-two/description/
*
* algorithms
* Easy (43.01%)
* Likes: 789
* Dislikes: 185
* Total Accepted: 322.1K
* Total Submissions: 740.7K
* Testcase Example: '1'
*
* Given an integer, write a function to determine if it is a power of two.
*
* Example 1:
*
*
* Input: 1
* Output: true
* Explanation: 2^0 = 1
*
*
* Example 2:
*
*
* Input: 16
* Output: true
* Explanation: 2^4 = 16
*
* Example 3:
*
*
* Input: 218
* Output: false
*
*/
namespace _231
{
// @lc code=start
public class Solution
{
public bool IsPowerOfTwo(int n) =>
n switch
{
int n1 when n1 > 0 => n != 0 && (n & (n - 1)) == 0,
_ => false,
};
}
// @lc code=end
}