当前位置:网站首页>Sword finger offer 03 Duplicate number in array
Sword finger offer 03 Duplicate number in array
2022-06-28 08:17:00 【wy_ forty-three million four hundred and thirty-one thousand ei】
The finger of the sword Offer 03. Repeated numbers in an array
Address of force deduction problem solution
The difficulty is simple 695
Find the repeated numbers in the array .
At a length of n Array of nums All the numbers in 0~n-1 Within the scope of . Some numbers in the array are repeated , But I don't know how many numbers are repeated , I don't know how many times each number has been repeated . Please find any duplicate number in the array .
Example 1:
Input :
[2, 3, 1, 0, 2, 5, 3]
Output :2 or 3
analysis
Declaration set , Determine whether the elements added to the collection are duplicate elements
Code
class Solution {
public int findRepeatNumber(int[] nums) {
Set<Integer> set=new HashSet<Integer>();
int repeat=-1;
for(int num:nums){
if(!set.add(num)){
repeat=num;
break;
}
}
return repeat;
}
}
边栏推荐
猜你喜欢

sql主从复制搭建

设置cmd的编码为utf-8

Little artist huangxinyang was invited to participate in the Wuhan station of children's unit of Paris Fashion Week

MySQL implements transaction persistence using redo logs

【js】-【DFS、BFS应用】-学习笔记

Redis02 -- an operation command of five data types for ending redis (it can be learned, reviewed, interviewed and collected for backup)

Introduction to kubernetes (I)

【学习笔记】拟阵

Host is not allowed to connect to this MySQL server

Almost Union-Find(带权并查集)
随机推荐
In flood fighting and disaster relief, the city donated 100000 yuan of love materials to help Yingde
探讨gis三维系统在矿山行业中的应用
22/02/14 study notes
[JS] - [throttling and anti shake function]
Priority of JS operator
Redis uses sentinel master-slave switching. What should the program do?
[learning notes] linear basis
开户券商怎么选择?网上开户是否安全么?
B_ QuRT_ User_ Guide(26)
AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
ROS notes (08) - definition and use of service data
设置网页的标题部分的图标
Devops Basics: Jenkins deployment and use (I)
SQL master-slave replication setup
Airflow2.1.1 summary of the pits stepped on in actual combat!!
2022巴黎时装周儿童单元6.19武汉站圆满落幕
抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
券商注册开户靠谱吗?安全吗?
Eslint 语法监测关闭
B_ QuRT_ User_ Guide(27)