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

缺失的第一个正整数

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

package com.hhdd.哈希;

import java.util.HashSet;

/**
 * @Author huanghedidi
 * @Date 2022/8/13 15:39
 */
public class 缺失的第一个正整数 {

    public int minNumberDisappeared(int[] nums) {
        // write code here
        HashSet<Integer> help = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            int tmp = nums[i];
            if (tmp > 0) {
                help.add(tmp);
            }
        }
        int start = 1;
        while (true) {
            if (help.contains(start)) {
                start++;
            } else {
                return start;
            }
        }
    }
}

全部评论

相关推荐

团子请爱我一次_十月...:不是戈门,干哪来了,这就是java嘛
点赞 评论 收藏
分享
面了100年面试不知...:头像换成柯南再试试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务