image_2021-11-15_01-17-38.png
32.5 KB
#N868. Binary Gap
problem link
#solution
problem link
#solution
class Solution {
public int binaryGap(int n) {
int res=0, d=-30;
while(n>0){
if(n%2==1){
res=Math.max(res, d);
d=0;
}
n=n/2;
d++;
}
return res;
}
}