Wednesday, December 19, 2018

868. Binary Gap

Version #1 Bit Manipulation
I saw someone check the bit '1' by checking num % 2 == 0
I think it is not as good as my method

 98.98 %
class Solution {
    public int binaryGap(int N) {
int counter = -1;
int max = 0;
while (N != 0) {
if ((N & 1) != 0) {
max = Math.max(max, counter);
counter = 0;
}
if (counter != -1) counter++;
N >>>= 1;
}
return max;
}
}

No comments:

Post a Comment