当前位置:网站首页>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]
}
}
};
边栏推荐
- Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC
- 电脑清理,删除的系统文件
- C語言雙指針——經典題型
- ROS compilation calls the third-party dynamic library (xxx.so)
- Deep anatomy of C language -- C language keywords
- 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
- Bitwise logical operator
- vb.net 随窗口改变,缩放控件大小以及保持相对位置
- LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
- Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
猜你喜欢
如何正确截取字符串(例:应用报错信息截取入库操作)
sublime text中conda环境中plt.show无法弹出显示图片的问题
Alibaba cloud server mining virus solution (practiced)
可变长参数
View computer devices in LAN
软件卸载时遇到trying to use is on a network resource that is unavailable
Restful API design specification
个人电脑好用必备软件(使用过)
Screenshot in win10 system, win+prtsc save location
Warning in install. packages : package ‘RGtk2’ is not available for this version of R
随机推荐
Revit secondary development Hof method calls transaction
LeetCode:673. 最长递增子序列的个数
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
C语言双指针——经典题型
企微服务商平台收费接口对接教程
如何进行接口测试测?有哪些注意事项?保姆级解读
MySQL uninstallation and installation methods
Charging interface docking tutorial of enterprise and micro service provider platform
vb. Net changes with the window, scales the size of the control and maintains its relative position
UML diagram memory skills
随手记01
LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
Sublime text using ctrl+b to run another program without closing other runs
Cesium draw points, lines, and faces
TDengine 社区问题双周精选 | 第三期
@JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
The problem and possible causes of the robot's instantaneous return to the origin of the world coordinate during rviz simulation
vb.net 随窗口改变,缩放控件大小以及保持相对位置
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
LeetCode:394. 字符串解码