当前位置:网站首页>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
}
边栏推荐
- Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
- 关于Steam 教育的知识整理
- AcrelEMS高速公路微电网能效管理平台与智能照明解决方案智慧点亮隧道
- Mysql重点难题(2)汇总
- Pyflink writes MySQL examples with JDBC
- Gin framework learning code
- Pit encountered in win11 pytorch GPU installation
- TypeScript函数详解
- Cubemx DMA notes
- Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
猜你喜欢
Summary of common string processing functions in C language
Practical problem solving ability of steam Education
Summary of main account information of zhengdaliu 4
数学知识(欧拉函数)
Preparation for writing SAP ui5 applications using typescript
How to recover deleted data in disk
Application of intelligent robot in agricultural ecology
UNET deployment based on deepstream
Vmware安装win10报错:operating system not found
How to write a client-side technical solution
随机推荐
Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
培养中小学生对教育机器人的热爱之心
Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
奠定少儿编程成为基础学科的原理
Promise all()
UNET deployment based on deepstream
Unity particle Foundation
Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
解决:代理抛出异常错误
Markdown编辑语法
Future trend of automated testing ----- self healing technology
C - derived classes and constructors
Knowledge arrangement about steam Education
数学知识(欧拉函数)
Introduction to Luogu 3 [circular structure] problem list solution
6.30 year end summary, end of student age
国产全中文-自动化测试软件Apifox
Mapping location after kotlin confusion
Application of intelligent robot in agricultural ecology
DJB Hash