当前位置:网站首页>LeetCode26: remove duplicates in sorted array
LeetCode26: remove duplicates in sorted array
2022-08-09 23:11:00 【Doraemon 0219】
Given you an array nums in ascending order, please delete the repeated elements in place, so that each element appears only once, and return the new length of the deleted array.The relative order of elements should remain consistent.
Because the length of the array cannot be changed in some languages, the result must be placed in the first part of the array nums.More canonically, if there are k elements after removing duplicates, then the first k elements of nums should hold the final result.
Return k after inserting the final result into the first k positions of nums .
Don't use extra space, you have to modify the input array in-place and do it with O(1) extra space.
Source: LeetCode
Link: https://leetcode.cn/problems/remove-duplicates-from-sorted-array
This topic adopts the double-pointer method. It is very interesting to see such a passage in the Likou comment area, which can help us understand this double-pointer method:

Double pointer method (C++)
Double pointer method is very useful in array and linked list problems.
class Solution {public:int removeDuplicates(vector&nums){int fast = 1;//fast pointerint slow = 0;//Slow pointerif(nums.size()==0)return 0;for(fast = 1;fast 边栏推荐
- Install Mysql8.0 on windos, and solve the problem of re-login exception ERROR 1045 (28000)
- 普源精电上半年扭亏为盈,高端产品持续发力!你看好仪器界“华为”吗?
- Don't use array.length-1 to get the last item of the array
- UE4_定序器控制蓝图对象
- Definition and Basic Operations of Sequence Tables
- PMP每日一练 | 考试不迷路-8.9(包含敏捷+多选)
- APP自动化测试框架-UiAutomator2基础入门
- MySQL慢查询的多个原因
- C语言预处理命令是什么?
- 万字总结:分布式系统的38个知识点
猜你喜欢

Unity2D_线框材质

Skywalking系列学习之Trace Profiling源码分析

Application of Acrel5000web Energy Consumption System in a College-Susie Week

Beat the interviewer, the CURD system can also make technical content

Access control knowledge

APP automation test framework - UiAutomator2 introductory

论文解读(DropEdge)《DropEdge: Towards Deep Graph Convolutional Networks on Node Classification》

Word文档怎么输入无穷大符号∞

TF生成均匀分布的tensor

线段相交的应用
随机推荐
What to do if Windows 11 can't find Internet Explorer
Word怎么设置图片衬于文字下方?两种方法教你设置Word图片衬于文字下方
题解:Edu Codeforces 109(div2)
Ali Ermi: Without accept, can a TCP connection be established?
QGIS编译SIP的问题
Interviewer: How to deal with Redis big key?
抽象类 or 接口
Word文档怎么输入无穷大符号∞
消防安全培训|“蓝朋友”,开课了!
Word怎么制作一张标准的答题卡?
Jensen (琴生) 不等式
如何让您的公司内容满足 GDPR 合规性
【stack】【queue】【priority_queue】【deque】Detailed explanation
数独 | 回溯-7
APP自动化测试框架-UiAutomator2基础入门
CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
Interpretation of the paper (DropEdge) "DropEdge: Towards Deep Graph Convolutional Networks on Node Classification"
DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides
AI+医疗:使用神经网络进行医学影像识别分析
Cookie、session、token