当前位置:网站首页>Leetcode: Jianzhi offer 03 Duplicate numbers in array
Leetcode: Jianzhi offer 03 Duplicate numbers in array
2022-07-06 08:51:00 【Bertil】
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
Limit :
- 2 <= n <= 100000
Their thinking
1. First, sort the array , Then iterate through the array , If adjacent elements are equal , Then return to
Code
/** * @param {number[]} nums * @return {number} */
var findRepeatNumber = function(nums) {
nums.sort()
for(let i = 0; i < nums.length - 1; i++){
if(nums[i] === nums[i + 1]) {
return nums[i]
}
}
};
边栏推荐
- vb.net 随窗口改变,缩放控件大小以及保持相对位置
- Detailed explanation of heap sorting
- C語言雙指針——經典題型
- 【嵌入式】使用JLINK RTT打印log
- Marathon envs project environment configuration (strengthen learning and imitate reference actions)
- Image, CV2 read the conversion and size resize change of numpy array of pictures
- 电脑清理,删除的系统文件
- Deep analysis of C language data storage in memory
- LeetCode:394. 字符串解码
- Philosophical enlightenment from single point to distributed
猜你喜欢

Detailed explanation of dynamic planning

Swagger setting field required is mandatory

Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines

sublime text中conda环境中plt.show无法弹出显示图片的问题
![[MySQL] multi table query](/img/eb/9d54df9a5c6aef44e35c7a63b286a6.jpg)
[MySQL] multi table query

Using C language to complete a simple calculator (function pointer array and callback function)

vb. Net changes with the window, scales the size of the control and maintains its relative position

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Double pointeur en langage C - - modèle classique

如何正确截取字符串(例:应用报错信息截取入库操作)
随机推荐
marathon-envs项目环境配置(强化学习模仿参考动作)
【嵌入式】使用JLINK RTT打印log
win10系统中的截图,win+prtSc保存位置
力扣每日一题(二)
LeetCode:236. 二叉树的最近公共祖先
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
LeetCode:剑指 Offer 03. 数组中重复的数字
Esp8266-rtos IOT development
UML diagram memory skills
egg. JS project deployment online server
【剑指offer】序列化二叉树
The problem and possible causes of the robot's instantaneous return to the origin of the world coordinate during rviz simulation
Generator parameters incoming parameters
Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
How to conduct interface test? What are the precautions? Nanny level interpretation
hutool优雅解析URL链接并获取参数
sublime text的编写程序时的Tab和空格缩进问题
visdom可视化实现与检查介绍
JVM quick start
View computer devices in LAN