Using BitSet--Java


  • 2
    6
    public int missingNumber(int[] nums) {
        int n=nums.length,i;
        BitSet bit=new BitSet();
        for(i=0;i<n;i++)
        	bit.set(nums[i]);
        for(i=0;i<n;i++)
        	if(!bit.get(i))break;
        return i;
    }

Log in to reply
 

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