当前位置:网站首页>[jzof-03] repeated numbers in the array
[jzof-03] repeated numbers in the array
2022-07-21 05:04:00 【Sighed, angry】
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 .
Input :
[2, 3, 1, 0, 2, 5, 3]
Output :2 or 3
Train of thought : Traverse + Use Set aggregate
Train of thought two : Replacement in place .
import java.util.*;
public class Solution {
/** * The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly * * * @param numbers int Integer one-dimensional array * @return int integer */
public int duplicate (int[] numbers) {
int i = 0;
while (i < numbers.length) {
if (numbers[i] == i) {
i++;
continue;
}
if (numbers[numbers[i]] == numbers[i]) {
return numbers[i];
}
int temp = numbers[i];
numbers[i] = numbers[temp];
numbers[temp] = temp;
}
return -1;
}
}
边栏推荐
- 原生threeJS入门
- A very simple and beautiful login box
- keras MNIST手写数字数据集数字识别
- With great power there must come great responsibility.
- Master these plug-ins and improve your office efficiency by 90% every minute!
- LeetCode刷题--点滴记录016
- Auto encoder
- 6 月威胁报告:新银行恶意软件 MaliBot 对移动银行用户构成威胁
- 【云原生之kubernetes】kubernetes集群下初始化容器的使用方法
- 文末送书|豆瓣9.4分,“hello,world”起源于这本书!
猜你喜欢
[FPGA tutorial case 31] communication case 1 - ask modulation signal generation based on FPGA
mpf4_定价欧式美式障碍Options_CRR_Leisen-Reimer_Greeks_二叉树三叉树网格_Finite differences(显式隐式)Crank-Nicolson_Imp波动率
Kotlin学习之json数据解析
Dynamic password lock based on stm32
What are the six access database objects? What is the most important difference between access and excel?
RNA 24. Timer, an online gadget for TCGA based analysis of immune infiltrating cells in SCI articles
在 IDEA 里下个五子棋不过分吧?
如何用二八原则理解软件测试,你且看下文
[team PK competition] the points mall has been opened | exchange exclusive gifts now
Learn how to choose chart types, and Xiaobai can also play with data analysis
随机推荐
Detailed explanation of five data types of redis
this的指向
【leetcode】150 逆波兰表达式求值
Router link opens a new page Jump and a tag to prevent default jump and various attributes
关于单细胞TPM、Count数据的处理 part1
【Jailhouse 文章】Scheduling Policies and System Software Architectures for Mixed-criticality...
【翻译】读博士一年后对机器学习工程的思考
已解决(最新版selenium报错)AttributeError: module ‘selenium.webdriver‘ has no attribute ‘PhantomJS‘
【学习笔记】Insert Addition
What are the advantages of low code platforms over traditional IT development?
阶跃数特征
文末送书|豆瓣9.4分,“hello,world”起源于这本书!
二维卷积中文微博情感分类项目
自编码器(Auto-Encoder)
VAE image generation practice
RNA 23. Risk factor association diagram of Cox model of expressed genes in SCI articles (ggrisk)
mpf4_ Pricing European American barrier options_ CRR_ Leisen-Reimer_ Greeks_ Binary tree trigeminal tree grid_ Fine differences (explicit implicit) crank Nicolson_ Imp volatility
Renren code generator -- simplify your development
《PolarDB for Postgres SQL 》主要讲了什么?
SCS [1] today starts a single-cell journey, describing the past and present lives of single-cell sequencing