/**给定一个包含 [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++;
- }
- }
- }
-
相关阅读:
Pytest框架实战二
深度学习_3_张量运算
KubeSphere 在互联网电商行业的应用实践
Pytorch安装
JVM——内存区域与内存溢出
如何在 Python 中运行无头浏览器?
Android Glide in RecyclerView,only load visible item when page return,Kotlin
79. 单词搜索
C++-JSON
Grafana系列-统一展示-8-ElasticSearch日志快速搜索仪表板
-
原文地址:https://blog.csdn.net/m0_72084166/article/details/133778913