A simple fast and efficient C# Solution


  • 0
    V

    A simple fast and efficient C# Solution

    public class Solution {
        public int FindComplement(int num) {
            int mask = 1;
            while(num > mask)
                mask = (mask << 1) | 1;
            return num ^ mask;
        }
    }
    

  • 0
    G

    we are the same

    public static int FindComplement(int num)
    {
    	int i = 1;
    	while (i < num)
    		i = i | (i << 1);
    	return ~num & i;
    }
    

Log in to reply
 

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