Java solution using bitset


  • 0
    H
    public static int firstMissingPositive(int[] nums) {
    	BitSet set = new BitSet();
    	for(int i = 0; i < nums.length; i++){
    		if(nums[i] >= 0){
    			set.set(nums[i]);
    		}
    	}
    	return set.nextClearBit(1);
    }

  • 1
    A

    @han38 Bitset grows dynamically. It does not qualify constant space O(1) requirement.


Log in to reply
 

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