Java straightforward solution


  • 0
    Y
    public class Solution {
        public int findComplement(int num) { 
            int tmp = num;
            int n = 1;
            while (tmp != 0) {
                tmp >>= 1;
                n <<= 1;
            }
            return n-num-1;
        }
    }
    

Log in to reply
 

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