Easy c++ without while and for


  • 2
    S
    class Solution {
    public:
        int findComplement(int num) {
            int c = (num | (num >> 1));
            c = (c | (c >> 2));
            c = (c | (c >> 4));
            c = (c | (c >> 8));
            c = (c | (c >> 16));
            return (~num & c);
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.