Leetcode 201. 数字范围按位与

class Solution {
public:
    int rangeBitwiseAnd(int m, int n) {
        int t=m&n,ans=0;
        n-=m;
        while(t){
            int k=t&-t;
            if(k>=n) ans+=k;
            t-=k;
        }
        return ans;
    }
};

你可能感兴趣的:(Leetcode 201. 数字范围按位与)