当前位置:网站首页>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
边栏推荐
猜你喜欢
消防安全培训|“蓝朋友”,开课了!
CMake installation upgrade higher version
[corctf 2022] section
Optimization of SQL Statements and Indexes
cadence中复制一部分PCB到另一个PCB中去
Access control knowledge
Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?
AI Knows Everything: Building and Deploying a Sign Language Recognition System from Zero
在VMware上安装win虚拟机
Problems with compiling SIP with QGIS
随机推荐
STC8H Development (15): GPIO Drives Ci24R1 Wireless Module
Jensen (琴生) 不等式
Tensorflow中使用convert_to_tensor去指定数据的类型
knn到底咋回事?
mysql多表左链接查询
必看设计干货|易知微设计师是怎么做标准可视化设计服务的?
Unity_平滑移动
什么是IDE(集成开发环境)?
Lyapp exponents and bifurcation diagrams for fractional chaotic systems
CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
技术分享 | 接口自动化测试之JSON Schema模式该如何使用?
Skywalking系列学习之Trace Profiling源码分析
mysql配置参数详解[通俗易懂]
LED闪烁 闪灯芯片IC 手电筒IC 闪灯控制IC 闪烁IC流水灯
PHP 二维数组根据某个字段排序
ACM MM 2022 | Cloud2Sketch: 长空云作画,AI笔生花
Tensorflow中placeholder函数的用法
C语言中的文件是什么?
Access Characteristics of Constructor under Inheritance Relationship
Definition and Basic Operations of Sequence Tables