当前位置:网站首页>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]
}
}
};
边栏推荐
- egg. JS directory structure
- 查看局域网中电脑设备
- 如何正确截取字符串(例:应用报错信息截取入库操作)
- Hutool gracefully parses URL links and obtains parameters
- Excellent software testers have these abilities
- View computer devices in LAN
- win10系统中的截图,win+prtSc保存位置
- R language uses the principal function of psych package to perform principal component analysis on the specified data set. PCA performs data dimensionality reduction (input as correlation matrix), cus
- Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
- C语言双指针——经典题型
猜你喜欢
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
Roguelike game into crack the hardest hit areas, how to break the bureau?
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
Charging interface docking tutorial of enterprise and micro service provider platform
Problems encountered in connecting the database of the project and their solutions
ESP8266-RTOS物联网开发
egg. JS getting started navigation: installation, use and learning
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
C語言雙指針——經典題型
Swagger setting field required is mandatory
随机推荐
UnsupportedOperationException异常
Pytorch view tensor memory size
企微服务商平台收费接口对接教程
@Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)
Purpose of computer F1-F12
LeetCode:214. 最短回文串
vb.net 随窗口改变,缩放控件大小以及保持相对位置
Mobile phones and computers on the same LAN access each other, IIS settings
Super efficient! The secret of swagger Yapi
【嵌入式】使用JLINK RTT打印log
Unsupported operation exception
pytorch查看张量占用内存大小
电脑F1-F12用途
LeetCode:41. 缺失的第一个正数
项目连接数据库遇到的问题及解决
Esp8266-rtos IOT development
C语言双指针——经典题型
[MySQL] limit implements paging
力扣每日一题(二)
可变长参数