share my simple java solution


  • 0
    L

    public class Solution {
    public int findComplement(int num) {
    int mask = 0xFFFFFFFF;
    int temp = num;
    while(temp>0){
    temp = temp >> 1;
    mask = mask << 1;
    }
    return mask ^ (~num);
    }
    }

    The idea is to find the '1' that should be set to '0';


Log in to reply
 

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