题解 | #缺失的第一个正整数#

缺失的第一个正整数

http://www.nowcoder.com/practice/50ec6a5b0e4e45348544348278cdcee5

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @return int整型
     */
    public int minNumberDisappeared (int[] nums) {
        // write code here
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < nums.length; i++){
            map.put(nums[i],1);
        }
        for(int i = 1; i < nums.length+1; i++){
            if(!map.containsKey(i)){
                return i;
            }
        }
        return nums.length+1;
    }
}
全部评论

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务