当前位置:网站首页>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
边栏推荐
- Mba-day5 Mathematics - application problems - engineering problems
- Detailed explanation of typora Grammar (I)
- GO接口使用
- Learning website materials
- Gets the current time in character format
- Visual Road (XII) detailed explanation of collection class
- Difference between pregnancy box and delivery box
- 防止web项目中的SQL注入
- Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
- SWAT—Samba WEB管理工具介绍
猜你喜欢
比深度学习更值得信赖的模型ART
CUMCM 2021-B:乙醇偶合制备C4烯烃(2)
Visual Road (XII) detailed explanation of collection class
An interesting interview question
Visual common drawing (V) scatter diagram
Detailed explanation of typora Grammar (I)
Manjaro installation and configuration (vscode, wechat, beautification, input method)
GO接口使用
Visual solutions to common problems (VIII) mathematical formulas
Reading integrity monitoring techniques for vision navigation systems - 5 Results
随机推荐
MySQL面试题讲解之如何设置Hash索引
学习网站资料
最强日期正则表达式
Pycharm
精彩回顾|「源」来如此 第六期 - 开源经济与产业投资
ffmpeg命令行常用参数
web三大组件(Servlet,Filter,Listener)
Esp32 learning - use and configuration of GPIO
Data analysis learning (I) data analysis and numpy Foundation
C语言之结构体(进阶篇)
MySQL分区表实现按月份归类
Alarm scene recognition
colab
Excel·VBA自定义函数获取单元格多数值
Special members and magic methods
Xdotool key Wizard
Mysql系列SQL查询语句书写顺序及执行顺序详解
面向全球市场,PlatoFarm今日登录HUOBI等全球四大平台
MBA-day5数学-应用题-工程问题
vm设置静态虚拟机