当前位置:网站首页>Implementation of go language for deleting duplicate items in sorting array
Implementation of go language for deleting duplicate items in sorting array
2022-07-02 05:00:00 【Jimmy_ jimi】
The goal is : Delete duplicates in sort array
To give you one Ascending order Array of nums , Would you please In situ Delete duplicate elements , Make each element Only once , Returns the new length of the deleted array . Elemental Relative order It should be maintained Agreement .
Because the length of an array cannot be changed in some languages , So you have to put the result in an array nums The first part of . More formally , If there is... After deleting duplicates k Elements , that nums Before k An element should hold the final result .
Insert the final result into nums Before k Return to... After a position k .
Don't use extra space , You must be there. In situ Modify input array And using O(1) Complete with extra space .
author : Power button (LeetCode)
link :https://leetcode.cn/leetbook/read/top-interview-questions-easy/x2gy9m/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
Result output :
// Double pointer
func removeDuplicates(nums []int) int {
//len() Take the length of the array
if (len(nums) == 0){
return 0
}
slow,fast := 0,0
for ; fast < len(nums); fast++{
if (nums[fast] != nums[slow]){
slow++
nums[slow] = nums[fast]
}
}
return slow+1
}
边栏推荐
- Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy
- Learn BeanShell before you dare to say you know JMeter
- Introduction to Luogu 3 [circular structure] problem list solution
- Future trend of automated testing ----- self healing technology
- leetcode存在重复元素go实现
- Summary of common string processing functions in C language
- Online incremental migration of DM database
- Change deepin to Alibaba image source
- 06 decorator mode
- Orthogonal test method and function diagram method for test case design
猜你喜欢
Go Chan's underlying principles
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
农业生态领域智能机器人的应用
What data does the main account of Zhengda Meiou 4 pay attention to?
About PROFIBUS: communication backbone network of production plant
Lm09 Fisher inverse transform inversion mesh strategy
06 decorator mode
Virtual machine installation deepin system
Leetcode merge sort linked list
Save the CDA from the disc to the computer
随机推荐
Typescript function details
Record the bug of unity 2020.3.31f1 once
[Yu Yue education] autumn 2021 reference materials of Tongji University
Preparation for writing SAP ui5 applications using typescript
Getting started with pytest ----- confitest Application of PY
Pit encountered in win11 pytorch GPU installation
Mathematical knowledge (Euler function)
Knowledge arrangement about steam Education
Leetcode merge sort linked list
Win10 disk management compressed volume cannot be started
Mysql重点难题(2)汇总
Lay the foundation for children's programming to become a basic discipline
Use of Baidu map
Leetcode basic programming: array
Pytest learning ----- pytest assertion of interface automation testing
DJB Hash
Go Chan's underlying principles
MMAP zero copy knowledge point notes
How do I interview for a successful software testing position? If you want to get a high salary, you must see the offer
List of common bugs in software testing