My java solution


  • 0
    W

    public int missingNumber(int[] nums) {
    int n = nums.length + 1;
    int[] array = new int[n];

        // initial the array
        for(int i = 0; i<n; i++) {
        	array[i] = 0;
        }
        
        for(int i = 0; i< nums.length; i++) {
        	array[nums[i]] = 1;
        }
        
        for(int i = 0; i<n; i++) {
        	if(array[i] == 0) {
        		return i;
        	}
        }
        
        return -1;
    }

Log in to reply
 

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