【leetcode】翻转数位

int reverseBits(int num){
    int max = 0,cnt = 0,cntPre = 0;
    while(num)
    {
        if(1 & num) cnt++;
        else
        {
            if(cntPre + cnt + 1 > max) max = cntPre + cnt + 1;
            cntPre = cnt;
            cnt = 0;
        }
        num >>= 1;
    }
    if(cntPre + cnt + 1 > max) max = cntPre + cnt + 1;
    return max;
}
原文地址:https://www.cnblogs.com/ganxiang/p/13628815.html