File tree Expand file tree Collapse file tree 1 file changed +21
-30
lines changed
Leetcode/Leetcode_August_Challenge Expand file tree Collapse file tree 1 file changed +21
-30
lines changed Original file line number Diff line number Diff line change @@ -42,34 +42,25 @@ public static boolean isPowerOfFour_log(int num) {
42
42
return Math .floor (logn ) == Math .ceil (logn );
43
43
}
44
44
45
- //approach 3
46
- static boolean isPowerOfFour2 (int num )
47
- {
48
- int count = 0 ;
49
-
50
- /*Check if there is
51
- only one bit set in n*/
52
- int x = num & (num - 1 );
53
-
54
- if ( num > 0 && x == 0 )
55
- {
56
- /* count 0 bits
57
- before set bit */
58
- while (num > 1 )
59
- {
60
- num >>= 1 ;
61
- count += 1 ;
62
- }
63
-
64
- /*If count is even
65
- then return true
66
- else false*/
67
- return (count % 2 == 0 ) ? true : false ;
68
- }
69
-
70
- /* If there are more than
71
- 1 bit set then n is not a
72
- power of 4*/
73
- return false ;
74
- }
45
+ // approach 3
46
+ static boolean isPowerOfFour2 (int num ) {
47
+ int count = 0 ;
48
+
49
+ // Check if there is only one bit set in num
50
+ int x = num & (num - 1 );
51
+
52
+ if (num > 0 && x == 0 ) {
53
+ // count 0 bits before set bit
54
+ while (num > 1 ) {
55
+ num >>= 1 ;
56
+ count += 1 ;
57
+ }
58
+
59
+ // If count is even then return true else false
60
+ return (count % 2 == 0 ) ? true : false ;
61
+ }
62
+
63
+ // If there are more than 1 bit set then num is not a power of 4
64
+ return false ;
65
+ }
75
66
}
You can’t perform that action at this time.
0 commit comments