not an efficient way, but easy to understand


  • 0
    C
                    List<Integer> result = new ArrayList<Integer>();
    		Set<Integer> set = new HashSet<Integer>();
    		for(int i = 0;i<nums.length;i++){
    			set.add(nums[i]);
    		}
    		for(int i = 1 ;i<=nums.length;i++) {
    			if(!set.contains(i)) {
    				result.add(i);
    			}
    		}
    		return result;
    

Log in to reply
 

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