Posted on

Description

Submission

class Solution {
public:
    int findComplement(int num) {
        int ret = 0;
        bool start = false;
        for(int i = 31; i >= 0; --i) {
            if((num >> i) & 1) start = true;
            if(start && ((num>>i) & 1) == 0) ret += (1 << i); 
        }
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *