当前位置:网站首页>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
边栏推荐
- Prometheus 运维工具 Promtool (四)TSDB 功能
- 巧用ngx_lua做流量分组
- uni-app进阶之创建组件/原生渲染
- In hot weather, the line of defense for safe production was strengthened, and Guangzhou Haizhu District carried out emergency drills for gas stations
- Oracle中的小知识
- 【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03
- 【云驻共创】企业数字化转型,华为云咨询与你同行
- (10) Defer keyword
- _HUGE and __IMP__HUGE in “math.h“
- What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system
猜你喜欢

LSA and optimization of OSPF

Skillfully use NGX_ Lua makes traffic grouping

office2013以上输入数学公式

ES(8.1)认证题目

为报复公司解雇,我更改了项目的所有代码注释!

13 probability distributions that must be understood in deep learning

The blind box of super primitive series will be launched soon, and platofarm will enable more rights and interests

选择供应商服务系统,是大健康产业企业迈向数字化转型的第一步

二分、三分、01分数规划 【第I弹】

工业品MRO采购网站有哪些优势?一文带你读懂
随机推荐
In the era of home health diagnosis, Senzo creates enhanced lateral flow test products
(10) Defer keyword
二维前缀和
Oracle中的小知识
关于软考高级要不要报班学习
定了!就在7月30日!
线程同步volatile与synchronized详解
Kubernetes
13 probability distributions that must be understood in deep learning
Function introduction and description of @jsontype annotation in fastjson
centos7下安装mysql,网上文章都不太准
JS promotion: the underlying principle of flat tiling
建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效
OSPF的LSA及优化
What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
初识SuperMap iDesktop
每天在岗不足8小时被辞?腾讯前员工追讨1300万加班费等,法院终审获赔9万
10分钟快速入门EVS【玩转华为云】
数据库mysql基础
Prometheus operation and maintenance tool promtool (IV) TSDB function