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

缺失的第一个正整数

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

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @return int整型
     */
    public int minNumberDisappeared (int[] nums) {
        // write code here
        for(int i =1;i<nums.length+1;i++){
            if(!isExist(nums,i))return i;
        }
        return nums.length+1;
    }
    boolean isExist(int[] arr,int num){
        for(int n:arr){
            if(num==n)return true;
        }
        return false;
    }
}

全部评论

相关推荐

头像
05-27 20:32
已编辑
深度学习
工行数据中心 偏运维养老 到手可能18w
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务