448. Find All Numbers Disappeared in an Array

来源:互联网 发布:mac 隐藏磁盘 编辑:程序博客网 时间:2024/04/28 01:59

Example:

Input:[4,3,2,7,8,2,3,1]Output:[5,6]

       1。无重复不一定用到set。 map比set更好用

public class Solution {    public List<Integer> findDisappearedNumbers(int[] nums) {        Map<Integer , Integer> map = new HashMap<>();for(int i = 0; i < nums.length; i++) {map.put(nums[i], nums[i]);}List<Integer> list = new ArrayList<>();for(int i = 1; i <= nums.length; i++) {if(!map.containsKey(i)) list.add(i);}    return list;    }}


0 0