LeetCode--Number Complement

Ideas:

    1. Take the highest digit of the number and fill it with zeros, then shift one place to the left, and then subtract one

    2. Invert the target number

    3. With

class Solution {
    public int findComplement(int num) {
        int mask=(Integer.highestOneBit(num)<<1)-1;
        num=~num;
        return mask#
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325647486&siteId=291194637