当前位置:网站首页>【LeetCode】287. Find duplicates
【LeetCode】287. Find duplicates
2022-06-10 01:32:00 【LawsonAbs】
1. subject
2. thought
Because the title says : == Only A repeated integer ==, This means that , When we keep exchanging , As long as you encounter the same number, you can return .
3. Code
class Solution:
def findDuplicate(self, nums: List[int]) -> int:
for i in range(len(nums)):
while(i != nums[i]-1):
idx = nums[i] - 1 # nums[i] This number should be placed in the subscript position of
if nums[i] == nums[idx]: # Find the result
return nums[i]
else:
nums[i],nums[idx] = nums[idx],nums[i] # swap
print(nums)
边栏推荐
- 面试必刷算法TOP101之字符串篇 TOP30
- [從零開始學習FPGA編程-16]:快速入門篇 - 操作步驟2-4- Verilog HDL語言描述語言基本語法(軟件程序員和硬件工程師都能看懂)
- How can win11 directly return to the desktop?
- 网络中的拥塞控制与数据传输
- 【LeetCode】461. 汉明距离
- 【ACL 2022】Hallucinated but Factual! Inspecting the Factuality of Hallucinations
- 1265_FreeRTOS中向任务就绪链表增加任务的实现分析
- Force deduction solution summary 497 random points in non overlapping rectangles
- What are the reasons for frequent channel drops in easycvr cascaded video convergence platform?
- Software engineering final review
猜你喜欢

Unity技术 - 2D项目经验
![[Multisim Simulation] differential proportional amplifier circuit](/img/29/951bee086128c1a0a4ec33ddc82bee.png)
[Multisim Simulation] differential proportional amplifier circuit

Nodejs报内部错误 TypeError: Cannot read property ‘destroy‘ of undefined的解决方法

Use the fiddler breakpoint to modify the request parameters and return parameters of an interface, intercept requests, and modify requests and responses

【ACL 2022】Hallucinated but Factual! Inspecting the Factuality of Hallucinations

Teaching Broad Reasoning Skills via Decomposition-Guided Contexts

Thingsboard tutorial (19): overview of rule nodes

How the computer system modifies the picture format

【ICLR 2022】Towards Continual Knowledge Learning of Language Models

985毕业,35岁创业失败,36岁回炉40岁被裁,中年夫妻无业咋办?
随机推荐
Disorder of flinksql
A junior college programmer in hupiao, he worked out with liuzhenhong while taking 22K offers
Eight consecutive championships! Inspur cloud has been the first in China's Government cloud market for 8 consecutive years
The gradient decline triggered a "heated debate" among AI bulls. Netizen: everyone's answer is worth seeing
[games101] Assignment 1 -- MVP (model, view, projection) transformation
MySQL script for Linux Installation
Custom action logging annotation
[image classification case] (10) three classifications of animal images of vision transformer, with complete pytoch code attached
What are the good techniques for domestic spot silver: simple usage of common indicators
Alleviate and repair Android studio Caton, kotlin code prompt is slow
Teaching Broad Reasoning Skills via Decomposition-Guided Contexts
【LeetCode】437.路径总和III
JVM records a CPU surge
Domain Adaptation and Graph Neural Networks
Think of GPL as a "virus"? Please stop defaming GPL
[email protected] 项目实训
TRichView and ScaleRichView 设置默认中文
Keep alive in TCP connection
Dependent auto assembly
DV和OV SSL证书哪个适合公司网站购买