448. Find All Numbers Disappeared in an Array


  • 0
    S
    • Create a new array of the same size as the input array
    • Iterate through the original array and place the numbers in the new array at an index number that matches the value of the number. For ex: if you find no. 5, place it at the 5th index in the new array.
    • The new array will now have some numbers and some zeros. All those zeros have the index number which is the missing number that we want.
    • Iterate through the new array and add the index number to the list whenever you find a zero.
    • Return the list.

    Code is attached below:
    '''
    class Solution {
    public List<Integer> findDisappearedNumbers(int[] nums) {

    		List<Integer> listy = new ArrayList<Integer>();
    
    	
    	int[] numsFinal = new int[nums.length];
    	
    	for(int i=0;i<nums.length;i++)
    	{
    		numsFinal[nums[i]-1]=nums[i];
    	}
    	
    	
    
    	for(int i=0;i<numsFinal.length;i++)
    	{
    		if(numsFinal[i]==0)
    		{
    			listy.add(i+1);
    		}
    	}
        
        return listy;
    }
    

    }
    '''


Log in to reply
 

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