当前位置:网站首页>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;
}
}
边栏推荐
- After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
- App automated testing appium Tutorial Part 1 - advanced supplementary content
- B_QuRT_User_Guide(26)
- Modifying the SSH default port when installing Oracle RAC makes CRS unable to install
- 2022第六季完美童模 佛山赛区 初赛圆满落幕
- Airflow2.1.1 ultra detailed installation document
- Installing mysql5.7 under Windows
- Introduction, compilation, installation and deployment of Doris learning notes
- Do you know TCP protocol (2)?
- ROS 笔记(08)— 服务数据的定义与使用
猜你喜欢
Connaissez - vous le protocole TCP (2)?
Three step problem of leetcode
The maximum number of Rac open file descriptors, and the processing of hard check failure
Ambari (VIII) --- ambari integrated impala document (valid for personal test)
Why MySQL cannot insert Chinese data in CMD
redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
App automated testing appium Tutorial Part 1 - advanced supplementary content
小艺人黄鑫洋受邀参加巴黎时装周儿童单元武汉站
AI首席架构师8-AICA-高翔 《深入理解和实践飞桨2.0》
关于在cmd中MySQL不能插中文数据的原因
随机推荐
Installing MySQL under Linux
B_QuRT_User_Guide(30)
Connaissez - vous le protocole TCP (2)?
微内核Zephyr获众多厂家支持!
Redis master-slave structure and application scenarios
SLAM中常用的雅克比矩阵J
[learning notes] linear basis
匿名页的反向映射
ROS 笔记(08)— 服务数据的定义与使用
[learning notes] search
Oracle view tablespace usage
Prometheus monitoring (I)
Is it reliable for securities companies to register and open accounts? Is it safe?
B_ QuRT_ User_ Guide(28)
【学习笔记】线性基
JS rounding tips
Configuring MySQL multi instance master-slave synchronization for Linux
Devops foundation chapter Jenkins deployment (II)
Eslint 语法监测关闭
The preliminary round of the sixth season of 2022 perfect children's model Foshan competition area came to a successful conclusion