File tree 2 files changed +21
-0
lines changed
August-LeetCoding-Challenge/04-Power-of-Four
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ //Solution 1
3
+ public bool IsPowerOfFour ( int num ) {
4
+ if ( num > 1 )
5
+ {
6
+ while ( num % 4 == 0 ) {
7
+ num /= 4 ;
8
+ }
9
+ }
10
+ return num == 1 ;
11
+ }
12
+
13
+ //Solution 2
14
+ public bool IsPowerOfFour ( int num ) {
15
+ //0x55555555 (hex) means 0101 0101 0101 0101 0101 0101 0101 0101 (binary)
16
+ return ( num > 0 )
17
+ && ( num & ( num - 1 ) ) == 0
18
+ && ( ( num & 0x55555555 ) != 0 ) ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Solutions in various programming languages are provided. Enjoy it.
10
10
1 . [ Detect Capital] ( https://github.com/AlgoStudyGroup/Leetcode/tree/master/August-LeetCoding-Challenge/01-Detect-Capital )
11
11
2 . [ Design HashSet] ( https://github.com/AlgoStudyGroup/Leetcode/tree/master/August-LeetCoding-Challenge/02-Design-HashSet )
12
12
3 . [ Valid Palindrome] ( https://github.com/AlgoStudyGroup/Leetcode/tree/master/August-LeetCoding-Challenge/03-Valid-Palindrome )
13
+ 4 . [ Power of Four] ( https://github.com/AlgoStudyGroup/Leetcode/tree/master/August-LeetCoding-Challenge/04-Power-of-Four )
13
14
14
15
## July LeetCoding Challenge
15
16
Click [ here] ( https://leetcode.com/explore/featured/card/july-leetcoding-challenge/ ) for problem descriptions.
You can’t perform that action at this time.
0 commit comments