当前位置:网站首页>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
}
边栏推荐
- js面试收藏试题1
- A new attribute value must be added to the entity entity class in the code, but there is no corresponding column in the database table
- 6.30年终小结,学生时代结束
- Getting started with pytest ----- confitest Application of PY
- DMA Porter
- Summary of database problems
- Rhcsa --- work on the fourth day
- [high speed bus] Introduction to jesd204b
- Comp 250 parsing
- Preparation for writing SAP ui5 applications using typescript
猜你喜欢
Common errors of dmrman offline backup
Record the bug of unity 2020.3.31f1 once
Getting started with pytest -- description of fixture parameters
[high speed bus] Introduction to jesd204b
How to configure PostgreSQL 12.9 to allow remote connections
One step implementation of yolox helmet detection (combined with oak intelligent depth camera)
Research on the security of ognl and El expressions and memory horse
正大留4的主账户信息汇总
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
Interview question: do you know the difference between deep copy and shallow copy? What is a reference copy?
随机推荐
2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路
Cubemx DMA notes
Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market
What data does the main account of Zhengda Meiou 4 pay attention to?
将光盘中的cda保存到电脑中
geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
Use of typescript classes
删除排序数组中的重复项go语言实现
Gin framework learning code
idea自動導包和自動删包設置
[quick view opencv] familiar with CV matrix operation with image splicing examples (3)
Mapping settings in elk (8) es
Mapping location after kotlin confusion
从数组中找出和为目标的下标
Idea autoguide package and autodelete package Settings
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
About PROFIBUS: communication backbone network of production plant
2022-003arts: recursive routine of binary tree
Practical problem solving ability of steam Education
解析少儿编程中的动手搭建教程