当前位置:网站首页>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
边栏推荐
- QT | some summaries of signals and slots
- Which strings will be resolved to null by fastjason?
- ES (8.1) certification topic
- Sort - quick sort (fast and slow pointer Implementation)
- 7.27 minimum spanning tree phased test problem solution
- 巧用ngx_lua做流量分组
- 不登高山,不知天之高也;不临深溪,不知地之厚也
- Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
- 语音聊天app——如何规范开发流程?
- Redis design specification
猜你喜欢

Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control

Boss: there are too many systems in the company. Can we realize account interworking?

arthas使用教程

13 probability distributions that must be understood in deep learning

In the era of home health diagnosis, Senzo creates enhanced lateral flow test products

It's settled! On July 30!

Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!

OSPF的拓展配置,选路原则,防环及重发布

API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试

Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
随机推荐
【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03
Skiasharp's WPF self drawn drag ball (case version)
2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
Redis面试题必知必会
centos7下安装mysql,网上文章都不太准
️雄关漫道真如铁,而今迈步从头越️
web之圣杯和双飞翼布局、float、clear、both
Description of landingsite electronic label quppa firmware entering DFU status
我用小程序容器让移动研发效率提升了5倍!
What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
CGAL编译错误
为报复公司解雇,我更改了项目的所有代码注释!
博弈论 1.Introduction(组合游戏基本概念、对抗搜索、Bash游戏、Nim游戏)
In hot weather, the line of defense for safe production was strengthened, and Guangzhou Haizhu District carried out emergency drills for gas stations
腾讯技术专家:解密亿级用户产品 微信、QQ、王者荣耀...全面上云实践!
What are the advantages of MRO purchasing website for industrial products? One article will help you understand
Skillfully use NGX_ Lua makes traffic grouping
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC
Introduction to thresholdfilter
【JZOF】15二进制中1的位数