当前位置:网站首页>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]
}
}
};
边栏推荐
- pytorch查看张量占用内存大小
- The mysqlbinlog command uses
- LeetCode:387. 字符串中的第一个唯一字符
- [Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
- [NVIDIA development board] FAQ (updated from time to time)
- Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC
- Pytorch view tensor memory size
- 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
- torch建立的网络模型使用torchviz显示
- What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
猜你喜欢
vb. Net changes with the window, scales the size of the control and maintains its relative position
LeetCode:236. 二叉树的最近公共祖先
What is CSRF (Cross Site Request Forgery)?
MYSQL卸载方法与安装方法
Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
多元聚类分析
marathon-envs项目环境配置(强化学习模仿参考动作)
Computer cleaning, deleted system files
LeetCode:221. 最大正方形
sublime text中conda环境中plt.show无法弹出显示图片的问题
随机推荐
torch建立的网络模型使用torchviz显示
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
Excellent software testers have these abilities
电脑F1-F12用途
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
【嵌入式】使用JLINK RTT打印log
Charging interface docking tutorial of enterprise and micro service provider platform
After reading the programmer's story, I can't help covering my chest...
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)
Export IEEE document format using latex
Problems in loading and saving pytorch trained models
The mysqlbinlog command uses
UML圖記憶技巧
Tcp/ip protocol
What are the common processes of software stress testing? Professional software test reports issued by companies to share
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
Philosophical enlightenment from single point to distributed
Detailed explanation of heap sorting
如何进行接口测试测?有哪些注意事项?保姆级解读
[NVIDIA development board] FAQ (updated from time to time)