当前位置:网站首页>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;
}
}
边栏推荐
- [learning notes] shortest path + spanning tree
- How to choose an account opening broker? Is it safe to open an account online?
- 22/02/14 study notes
- [shangpinhui] project notes
- LeetCode之三步问题
- After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
- B_ QuRT_ User_ Guide(27)
- redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
- AI首席架构师8-AICA-高翔 《深入理解和实践飞桨2.0》
- Unity - use of API related to Pico development input system ---c
猜你喜欢
随机推荐
JS rounding tips
sql主从复制搭建
Two tips for block level elements
设置网页的标题部分的图标
Study notes 22/1/18
Redis uses sentinel master-slave switching. What should the program do?
Oracle RAC -- understanding of VIP
22/02/15 study notes
【学习笔记】线性基
[learning notes] simulation
nlp序列完全可以模拟人脑智能
Activity隐式跳转
Ambari (IX) --- use expect to realize no interaction in ambri server setup phase (valid for personal test)
【学习笔记】差分约束
Connaissez - vous le protocole TCP (2)?
[shangpinhui] project notes
Hidden scroll bar on PC
PC端隐藏滚动条
PMP从报考到拿证基本操作,了解PMP必看篇
MySQL row format parsing

![[shangpinhui] project notes](/img/aa/043dd16c20348f1f80ca5e9e4ad330.png)






