当前位置:网站首页>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;
}
}
边栏推荐
- Oracle view tablespace usage
- ROS notes (09) - query and setting of parameters
- redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
- MySQL two table connection principle (understand join buf)
- Buffer pool in MySQL
- MySQL tablespace parsing
- 22/02/14 study notes
- Redis uses sentinel master-slave switching. What should the program do?
- 整数划分
- MySQL implements transaction persistence using redo logs
猜你喜欢

After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)

找合适的PMP机构只需2步搞定,一查二问

Two tips for block level elements

MySQL row format parsing

Jacobian matrix J commonly used in slam

【尚品汇】项目笔记

SLAM中常用的雅克比矩阵J

Introduction, compilation, installation and deployment of Doris learning notes

Redis cerebral fissure

B_ QuRT_ User_ Guide(27)
随机推荐
Uvcgan: unt vision transformer cycle-consistent Gan for unpropared image-to-image translation
【学习笔记】线性基
sql分析(查询截取分析做sql优化)
Redis persistence problem and final solution
Not so Mobile
In flood fighting and disaster relief, the city donated 100000 yuan of love materials to help Yingde
ROS notes (09) - query and setting of parameters
AI首席架构师8-AICA-高翔 《深入理解和实践飞桨2.0》
Is it reliable to open an account by digging money? Is it safe?
Little artist huangxinyang was invited to participate in the Wuhan station of children's unit of Paris Fashion Week
【js】-【节流、防抖函数】
解决npm ERR! Unexpected end of JSON input while parsing near问题
Prometheus + grafana + MySQL master-slave replication + host monitoring
Installing mysql5.7 under Windows
Prometheus deployment alarm docking QQ mailbox
Generation and verification of JWT token
After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
cuda和cudnn和tensorrt的理解
Prometheus monitoring (I)
你了解TCP协议吗(一)?