当前位置:网站首页>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
边栏推荐
- Jmeter 使用正则表达式提取器将返回值全部保存到一个文件中
- Tensorflow中placeholder函数的用法
- 数独 | 回溯-7
- Ankerui supports Ethernet communication, profibus communication embedded energy meter APM guiding technical requirements-Susie Week
- XXE-XML外部实体注入-知识点
- SQLi-LABS Page-2 (Adv Injections)
- 论文解读(DropEdge)《DropEdge: Towards Deep Graph Convolutional Networks on Node Classification》
- AI Knows Everything: Building and Deploying a Sign Language Recognition System from Zero
- SecureCRT强制卸载
- PMP每日一练 | 考试不迷路-8.9(包含敏捷+多选)
猜你喜欢
人人都可以DIY的大玩具,宏光MINIEV GAMEBOY产品力强,出行新装备
Unity2D_线框材质
Word怎么制作双面席卡?使用Word制作双面席卡方法
几种绘制时间线图的方法
Skywalking系列学习之Trace Profiling源码分析
Don't use array.length-1 to get the last item of the array
Reinforcement Learning Weekly Issue 57: DL-DRL, FedDRL & Deep VULMAN
Number of daffodils within a thousand
小黑leetcode清爽雨天之旅,刚吃完宇飞牛肉面、麻辣烫和啤酒:112. 路径总和
[corctf 2022] 部分
随机推荐
Definition and Basic Operations of Sequence Tables
Unity2D_线框材质
Skywalking系列学习之Trace Profiling源码分析
小黑leetcode之旅:94. 二叉树的中序遍历(补充Morris 中序遍历)
技术分享 | 接口自动化测试之JSON Schema模式该如何使用?
Two methods of implementing inverted strings in C language
Wps下划线怎么弄?Wps添加下划线的最全方法
线段相交的应用
linux定时执行sql文件[通俗易懂]
Access control knowledge
gmail+mtalk配合打免费网络电话。
SecureCRT背景配色
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified silica particles
windos安装Mysql8.0,及解决重新登录异常问题 ERROR 1045 (28000)
Lyapp exponents and bifurcation diagrams for fractional chaotic systems
编程语言中,取余和取模的区别
【stack】【queue】【priority_queue】【deque】Detailed explanation
自监督学习 —— MoCo v2
Unity_平滑移动
CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源