当前位置:网站首页>26. Delete duplicates in ordered array
26. Delete duplicates in ordered array
2022-04-23 11:04:00 【Programming share】
26. Remove duplicate items from an ordered array
Title Description
Click the direct topic link
26. Remove duplicate items from an ordered array
Their thinking
We use two subscripts i,j marked .i Traverse the array ,j Used for and i Compare the corresponding numbers . Move at different times .
How to play it :
i,j
Start with the matching search , When i,j
Number of points equal
when ,i Move ,j Immobility
. When i and j Number of points It's not equal
when ,j Move a bit
, And then put i The corresponding value is overwritten to j Corresponding value
, next i
Move again . until i
Traverse the entire array .
Code
int removeDuplicates(int* nums, int numsSize){
int i=0,j=0;
while(i<numsSize)
{
if(nums[i]==nums[j])
{
i++;
}
else
{
j++;
nums[j]=nums[i];
i++;
}
}
return j+1;
}
版权声明
本文为[Programming share]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231053220845.html
边栏推荐
- STM32接电机驱动,杜邦线供电,然后反烧问题
- Difference between pregnancy box and delivery box
- Facing the global market, platefarm today logs in to four major global platforms such as Huobi
- Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
- Ueditor -- limitation of 4m size of image upload component
- C语言之结构体(进阶篇)
- ConstraintLayout布局
- Visual common drawing (IV) histogram
- ID number verification system based on visual structure - Raspberry implementation
- Constraintlayout layout
猜你喜欢
VIM + ctags + cscope development environment construction guide
CUMCM 2021-b: preparation of C4 olefins by ethanol coupling (2)
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
ConstraintLayout布局
Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
Ueditor -- limitation of 4m size of image upload component
高价买来的课程,公开了!phper资料分享
How to quickly download vscode
第六站神京门户-------手机号码的转换
随机推荐
Jupyter Lab 十大高生产力插件
Data analysis learning (I) data analysis and numpy Foundation
Reading integrity monitoring techniques for vision navigation systems - 5 Results
闹钟场景识别
学习 Go 语言 0x02:对切片 Slice 的理解
MBA-day5数学-应用题-工程问题
Software testers, how to mention bugs?
Manjaro installation and configuration (vscode, wechat, beautification, input method)
Source insight 4.0 FAQs
Excel·VBA自定义函数获取单元格多数值
Typora operation skill description (I)
How to Ping Baidu development board
CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
Derivation and regularization
26. 删除有序数组中的重复项
About the three commonly used auxiliary classes of JUC
第六站神京门户-------手机号码的转换
web三大组件(Servlet,Filter,Listener)
Latex usage
学习 Go 语言 0x07:《Go 语言之旅》中 Stringer 练习题代码