/**给定一个包含 [0, n] 中 n 个数的数组 nums ,找出 [0, n] 这个范围内没有出现在数组中的那个数。 示例 1: 输入:nums = [3,0,1] 输出:2 解释:n = 3,因为有 3 个数字,所以所有的数字都在范围 [0,3] 内。2 是丢失的数字,因为它没有出现在 nums 中。*/
- public class Demo27 {
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- System.out.println("请输入最大数");
- int n=sc.nextInt();
- int[] nums=new int[n];
- System.out.println("请依次输入"+n+"个数");
- for (int i = 0; i
- nums[i]=sc.nextInt();
- }
- Arrays.sort(nums);
- int a=0;
- for (int i = 0; i
- if(nums[i]!=a){
- System.out.println(a);
- return;
- }
- a++;
- }
- }
- }
-
相关阅读:
数据结构:AVL树的实现和全部图解
使用CLion和gdb server debug haproxy
Linux运维相关基础知识
微信小程序开发(九):使用扩展组件库
【C语言】用函数实现模块化程序设计
Worthington丨Worthington胰蛋白酶化学性质及相关研究
Git基本应用<一>:Git安装及GitHub连接
篇(18)-Asp.Net Core入门实战-文章管理之文章内容管理(下拉框二级结构递归)
7. 通配符和正则表达式
CDGA|到底怎么才能做好数据治理呢?
-
原文地址:https://blog.csdn.net/m0_72084166/article/details/133778913