当前位置:网站首页>LeetCode:剑指 Offer 03. 数组中重复的数字
LeetCode:剑指 Offer 03. 数组中重复的数字
2022-07-06 08:44:00 【Bertil】
找出数组中重复的数字。
在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。
示例 1:
输入:
[2, 3, 1, 0, 2, 5, 3]
输出:2 或 3
限制:
- 2 <= n <= 100000
解题思路
1.首先对数组进行排序,然后遍历数组,如果出现相邻元素相等,则返回即可
代码
/** * @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]
}
}
};
边栏推荐
- Hutool gracefully parses URL links and obtains parameters
- hutool优雅解析URL链接并获取参数
- egg. JS project deployment online server
- MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
- 电脑清理,删除的系统文件
- R language ggplot2 visualization: place the title of the visualization image in the upper left corner of the image (customize Title position in top left of ggplot2 graph)
- Revit 二次开发 HOF 方式调用transaction
- Double pointeur en langage C - - modèle classique
- PLT in Matplotlib tight_ layout()
- View computer devices in LAN
猜你喜欢
[brush questions] top101 must be brushed in the interview of niuke.com
Roguelike game into crack the hardest hit areas, how to break the bureau?
【ROS】usb_cam相机标定
Navicat premium create MySQL create stored procedure
[MySQL] database stored procedure and storage function clearance tutorial (full version)
2022.02.13 - NC002. sort
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
Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
个人电脑好用必备软件(使用过)
Excellent software testers have these abilities
随机推荐
ROS编译 调用第三方动态库(xxx.so)
China polyether amine Market Forecast and investment strategy report (2022 Edition)
Deep anatomy of C language -- C language keywords
sys. argv
被破解毁掉的国产游戏之光
swagger设置字段required必填
【MySQL】鎖
Variable length parameter
Cisp-pte practice explanation
ESP8266-RTOS物联网开发
Detailed explanation of heap sorting
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
sublime text的编写程序时的Tab和空格缩进问题
[MySQL] log
Bottom up - physical layer
按位逻辑运算符
pytorch训练好的模型在加载和保存过程中的问题
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
Process of obtaining the electronic version of academic qualifications of xuexin.com
Light of domestic games destroyed by cracking