int binaryGap(int n){
    int max=0, pre=-1, cnt=0;
    while(n){       
        if((n&1) == 1 ){
            if(pre>=0 && cnt-pre > max)
                max=cnt-pre;
            pre=cnt;
        }
        cnt++;
        n>>=1;
    }
    return max;
}