当前位置:网站首页>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]
}
}
};
边栏推荐
- win10系统中的截图,win+prtSc保存位置
- 深度剖析C语言指针
- LeetCode:394. 字符串解码
- C语言双指针——经典题型
- [Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
- Deep analysis of C language pointer
- 目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
- 优秀的软件测试人员,都具备这些能力
- LeetCode:34. 在排序数组中查找元素的第一个和最后一个位置
- 可变长参数
猜你喜欢

Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges

Esp8266-rtos IOT development

Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges

【ROS】usb_ Cam camera calibration

Delay initialization and sealing classes

Computer graduation design PHP Zhiduo online learning platform

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

vb.net 随窗口改变,缩放控件大小以及保持相对位置

Detailed explanation of heap sorting

sublime text中conda环境中plt.show无法弹出显示图片的问题
随机推荐
Leetcode: Sword Finger offer 42. Somme maximale des sous - tableaux consécutifs
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
Super efficient! The secret of swagger Yapi
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
UML圖記憶技巧
同一局域网的手机和电脑相互访问,IIS设置
704 binary search
UML diagram memory skills
[MySQL] limit implements paging
Double pointeur en langage C - - modèle classique
LeetCode:236. 二叉树的最近公共祖先
Computer graduation design PHP Zhiduo online learning platform
win10系统中的截图,win+prtSc保存位置
Alibaba cloud server mining virus solution (practiced)
vb. Net changes with the window, scales the size of the control and maintains its relative position
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
[Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
Deep analysis of C language pointer
【嵌入式】使用JLINK RTT打印log