39-Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array My Submissions QuestionEditorial Solution
Total Accepted: 127836 Total Submissions: 381794 Difficulty: Easy
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array nums = [1,1,2],
Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn’t matter what you leave beyond the new length.
Submission Details
161 / 161 test cases passed.
Status: Accepted
Runtime: 32 ms
思路:so easy
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
size_t n = nums.size();
int count=0,i=0;
while(i<n){
if(i>0&&nums[i]==nums[i-1])count++;
else nums[i-count] = nums[i];
i++;
}
return n-count;
}
};
39-Remove Duplicates from Sorted Array的更多相关文章
- 26. Remove Duplicates from Sorted Array
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- Remove Duplicates From Sorted Array
Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...
- 【leetcode】Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
- 50. Remove Duplicates from Sorted Array && Remove Duplicates from Sorted Array II && Remove Element
Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...
- LeetCode:Remove Duplicates from Sorted Array I II
LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...
- 【26】Remove Duplicates from Sorted Array
[26]Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such th ...
- leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法
Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...
- [Leetcode] Remove Duplicates From Sorted Array II (C++)
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
随机推荐
- [no code][scrum meeting] Alpha 1
项目 内容 会议时间 2020-04-06 会议主题 团队任务分析与拆解 会议时长 30min 参会人员 全体成员 $( "#cnblogs_post_body" ).catalo ...
- 难搞的C语言指针你搞懂了多少
C语言指针说难不难但是说容易又是最容易出错的地方,因此不管是你要做什么只要用到C指针你就跳不过,今天咱们就以 十九个例子来给大家简单的分析一下指针的应用,最后会有C语言视频资料提供给大家更加深入的参考 ...
- STM32 禁用或开启总中断
今天把之前自己的一些在中断方面所产生的疑惑把具体的解决办法给大家分享一下,希望能够帮到大家. STM32在使用时有时需要禁用全局中断,比如MCU在升级过程中需禁用外部中断,防止升级过程中外部中断触发导 ...
- 我的一些JAVA基础见解
这个学期学习JAVA基础课,虽说之前都自学过,但在学习时仍可以思考一些模糊不清的问题,可以更深一步的思考.在这里写下一些需要深入的知识点,对小白们也很友好~ 一.Java数据类型 1.基本数据类型 这 ...
- ahb时序解析
ahb 总线架构 AHB(Advanced High Performance Bus)总线规范是AMBA(Advanced Microcontroller Bus Architecture) V2.0 ...
- 当src获取不到图片,onerror可指定一张默认的图片
<img src="img/789.png" onerror="javascript:this.src='img/123.png';" alt=" ...
- APP自动化环境搭建之appium工具介绍(二)
1.下载解压android-sdk-windows-appium //配置环境: ANDROID_HOME:D:\android-sdk-windows-appium path:...;%ANDROI ...
- Mysql - 如何决定用 datetime、timestamp、int 哪种类型存储时间戳?
背景 数据表都很可能会有一两个字段需要保存日期时间数据,那应该用什么 Mysql 类型来保存呢? 前面讲过 datetime.timestamp.int 的方式来保存日期时间 如何存储 10位.13位 ...
- Idea tomcat debug按钮灰色无法运行
打开Project Structure 2.选中src,点击按钮关闭界面,重启idea即可
- Jquery的常用使用方法
1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...