当前位置:网站首页>2. Output one of the repeated numbers in the array
2. Output one of the repeated numbers in the array
2022-07-28 10:16: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 Is an array , It's in there int Data of type , And then define a int Variable of type num, Every cycle , From nums Take a data from the array to print
- int : Indicates the type of collection you want to traverse
nums: Indicates the name of the set you want to traverse
num: Means that you traverse each element in the set It is stored in this variable
for example : Array {2,3,4,2,0,8,6,9,10}
for the first time :nums [2,3,4,2,0,8,6,9,10]
dic [2]
The second time :nums [2,3,4,2,0,8,6,9,10]
dic [2,3]
third time :nums [2,3,4,2,0,8,6,9,10]
dic [2,3,4]
The fourth time :nums [2,3,4,2,0,8,6,9,10]
dic [2,3,4]
Output :2
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958225181.html
边栏推荐
猜你喜欢

LSA and optimization of OSPF

二维前缀和

初识SuperMap iDesktop

5、动态规划---斐波那契数列

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

Aqua Data Studio 18.5.0导出insert语句

ES(8.1)认证题目
![[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC](/img/16/e5aa43df6ef9bdbc173fa547c85559.png)
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC

C语言 二级指针详解及示例代码

Digital construction of pharmaceutical industry is on the verge
随机推荐
2021-10-13arx
Irregular area of OSPF, LSA and serial number
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
14、双指针——盛最多水的容器
2. 输出数组中重复的数字之一
什么样的知识付费系统功能,更有利于平台与讲师发展?
记录一次idea中的父子项目修改project与module名称,亲测!
Elk real time log analysis platform
4.调整数组顺序使奇数位于偶数前面
Netease written test No. 2 -- typical application of European distance
Cloudcompare & PCL matching point sampling consistency suppression
Skiasharp's WPF self drawn drag ball (case version)
软件设计师考前20问,注意啦!!
Holy Grail of web and double wing layout, float, clear, both
基于docker安装MySQL
Redis面试题必知必会
2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
a different object with the same identifier value was already associated with the session
LinkedList源码按摩,啊舒服
Consul