当前位置:网站首页>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
边栏推荐
- Cookie、session、token
- SQL语句及索引的优化
- Definition and Basic Operations of Sequence Tables
- MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
- Application of Acrel5000web Energy Consumption System in a College-Susie Week
- 抽象类 or 接口
- Byte side: Can TCP and UDP use the same port?
- XXE-XML外部实体注入-知识点
- Error when source install/setup.bash
- Jmeter 使用正则表达式提取器将返回值全部保存到一个文件中
猜你喜欢
PMP每日一练 | 考试不迷路-8.9(包含敏捷+多选)
Excel如何打出正负号?Excel打出正负号的方法
DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
在VMware上安装win虚拟机
消防安全培训|“蓝朋友”,开课了!
PMP daily practice | didn't lost a 8.9 (including agile + multi-select)
Problems with compiling SIP with QGIS
LoRa无线技术在物联网应用市场的概况和发展
定投的基金
随机推荐
Don't tell me to play, I'm taking the PMP exam: what you need to know about choosing an institution for the PMP exam
什么是IDE(集成开发环境)?
自监督学习 —— MoCo v2
Lyapp exponents and bifurcation diagrams for fractional chaotic systems
SecureCRT强制卸载
PHP 二维数组根据某个字段排序
PMP每日一练 | 考试不迷路-8.9(包含敏捷+多选)
laravel 表迁移报错[通俗易懂]
Interviewer: How to deal with Redis big key?
SecureCRT背景配色
AI识万物:从0搭建和部署手语识别系统
An overall security understanding and method of cyberspace based on connection and security entropy
MySQL慢查询的多个原因
Cholesterol-PEG-Thiol, CLS-PEG-SH, Cholesterol-PEG-Sulfhydryl for improved solubility
L3-2 至多删三个字符 (30 分)
CMake installation upgrade higher version
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?
TF生成均匀分布的tensor
Endpoint mode for NetCore routing
同步锁synchronized追本溯源