当前位置:网站首页>2. 输出数组中重复的数字之一
2. 输出数组中重复的数字之一
2022-07-28 09:58:00 【[email protected]】
public int findRepeatNumber(int[] nums) {
Set<Integer> dic = new HashSet<>();
for(int num : nums){
if(dic.contains(num)) return num;
dic.add(num);
}
return -1;
}
for(int num : nums)
- nums是一个数组,里面放的是int类型的数据,然后定义了一个int类型的变量num,每循环一次,就从nums数组中取出一个数据来打印
- int :表示你要遍历的集合的类型
nums:表示你要遍历的集合的名
num:表示你每遍历集合中一个元素 便存储到该变量中
例如:数组{2,3,4,2,0,8,6,9,10}
第一次:nums [2,3,4,2,0,8,6,9,10]
dic [2]
第二次:nums [2,3,4,2,0,8,6,9,10]
dic [2,3]
第三次:nums [2,3,4,2,0,8,6,9,10]
dic [2,3,4]
第四次:nums [2,3,4,2,0,8,6,9,10]
dic [2,3,4]
输出:2
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zjj1910066023/article/details/124560932
边栏推荐
- On July 13, 2021, we collapsed like this
- 排序——快速排序(快慢指针实现)
- 基于docker安装MySQL
- 图解 3 种主流企业架构模式(建议收藏!)
- JWT login authentication + token automatic renewal scheme, well written!
- Arthas tutorial
- ASP.NET Core 6框架揭秘实例演示[29]:搭建文件服务器
- [esp32][esp idf] esp32s3 quickly build lvglv7.9
- 7.27 minimum spanning tree phased test problem solution
- 关于软考高级要不要报班学习
猜你喜欢

Thinking and summary of technical personnel | R & D Efficiency

软件设计师考前20问,注意啦!!

【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03

二维前缀和

Digital construction of pharmaceutical industry is on the verge

Redis面试题必知必会

What are the advantages of MRO purchasing website for industrial products? One article will help you understand

Joint search set

2022 uni app parsing token standard - use jsrsasign - climb the pit

Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
随机推荐
Thinking and summary of technical personnel | R & D Efficiency
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology
安装gmp
选择供应商服务系统,是大健康产业企业迈向数字化转型的第一步
Double pointer technique
jvm原理
银行入职考试要点汇总
Read Plato farm's eplato and the reason for its high premium
网易笔试之不要二——欧式距离的典型应用
线程同步volatile与synchronized详解
Illustrate three mainstream enterprise architecture models (recommended collection!)
OSPF的拓展配置,选路原则,防环及重发布
2021-10-13arx
uni-app进阶之创建组件/原生渲染
LIBCMTD.lib
JWT login authentication + token automatic renewal scheme, well written!
Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment
uni-app进阶之生命周期
10分钟快速入门EVS【玩转华为云】
Sizebasedtriggingpolicy introduction