File tree Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace Leetcode231_PowerOfTwo
8
+ {
9
+ /// <summary>
10
+ /// Leetcode 231: Power of two
11
+ /// https://leetcode.com/problems/power-of-two/description/
12
+ /// </summary>
13
+ class Program
14
+ {
15
+ static void Main ( string [ ] args )
16
+ {
17
+ }
18
+
19
+ /// <summary>
20
+ /// 0 - false
21
+ /// 1 - true
22
+ /// 2 - true
23
+ /// 3 - false
24
+ /// 4 - true
25
+ /// </summary>
26
+ /// <param name="n"></param>
27
+ /// <returns></returns>
28
+ public bool IsPowerOfTwo ( int n )
29
+ {
30
+ if ( n <= 0 )
31
+ return false ;
32
+
33
+ if ( n == 1 )
34
+ return true ;
35
+
36
+ if ( n % 2 == 1 )
37
+ return false ;
38
+
39
+ return IsPowerOfTwo ( n / 2 ) ;
40
+ }
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace Leetcode231_PowerOfTwo
8
+ {
9
+ /// <summary>
10
+ /// Leetcode 231: Power of two
11
+ /// https://leetcode.com/problems/power-of-two/description/
12
+ /// </summary>
13
+ class Program
14
+ {
15
+ static void Main ( string [ ] args )
16
+ {
17
+ }
18
+
19
+ /// <summary>
20
+ /// 0 - false
21
+ /// 1 - true
22
+ /// 2 - true
23
+ /// 3 - false
24
+ /// 4 - true
25
+ /// </summary>
26
+ /// <param name="n"></param>
27
+ /// <returns></returns>
28
+ public bool IsPowerOfTwo ( int n )
29
+ {
30
+ if ( n <= 0 )
31
+ return false ;
32
+
33
+ if ( n == 1 )
34
+ return true ;
35
+
36
+ if ( n % 2 == 1 )
37
+ return false ;
38
+
39
+ return IsPowerOfTwo ( n / 2 ) ;
40
+ }
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments