Remove Duplicates from Sorted Array 从排序数组中删除重复
来源:互联网 发布:mac上玩的游戏 编辑:程序博客网 时间:2024/05/04 12:33
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.
class Solution {public: int removeDuplicates(vector<int>& nums) { if(nums.size()<2) return nums.size(); int index = 0; for(int i=1;i<nums.size();i++){ if(nums[index] != nums[i]){ index++; nums[index] = nums[i]; } } return index + 1; }};
0 0
- Remove Duplicates from Sorted Array 从排序数组中删除重复
- 26. Remove Duplicates from Sorted Array(从排序数组中删除重复) —— Java
- LeetCode: Remove Duplicates from Sorted Array II(在排序数组中删除重复元素)
- leetcode 26. Remove Duplicates from Sorted Array从排序数组中移出重复元素(双指针)
- Remove Duplicates from Sorted Array 删除数组中的重复元素
- LinCode Remove Duplicates from Sorted Array 删除排序数组中的重复数字
- LintCode Remove Duplicates from Sorted Array II 删除排序数组中的重复数字 II
- 100.Remove Duplicates from Sorted Array-删除排序数组中的重复数字(容易题)
- 26. Remove Duplicates from Sorted Array(删除已排序数组中的重复数)-two pointers
- LeetCode 26 Remove Duplicates from Sorted Array(从已排序数组中移除重复元素)
- LeetCode 26 Remove Duplicates from Sorted Array(从已排序数组中移除重复元素)
- Leetcode 80. Remove Duplicates from Sorted Array II(从已排序数组中移除重复元素)
- LeetCode OJ 之 Remove Duplicates from Sorted Array(删除有序数组中重复的数)
- Remove Duplicates from Sorted Array--从有序数组中移除重复元素
- leetcode:Remove Duplicates from Sorted Array去掉排序数组中重复的元素
- Remove Duplicates from Sorted Array——移除排序数组中重复元素
- [leetcode 26]Remove Duplicates from Sorted Array——移除排序数组中重复元素
- leetCode 80.Remove Duplicates from Sorted Array II (删除排序数组中的重复II) 解题思路和方法
- 如何成为一个会使用jquery ui写界面的网站开发者
- Eclipse中使用Android50新特性CardView
- linux chkconfig配置自启动shell
- el逻辑表达式自然语言和逻辑符号之间的对应
- springmvc+mybatis+spring 整合 bootstrap html5 mysql oracle SSM框架源码 SSH maven
- Remove Duplicates from Sorted Array 从排序数组中删除重复
- Activity间数据传输原理图解
- oracle存储过程常用技巧
- 汇编比较两个字符串
- Unity C# 自定义TCP传输协议以及封包拆包、解决粘包问题(网络应用层协议)
- 证明:二分图中的环只能是偶环,不可能是奇环
- 有效便捷的爬取网站
- wordpress查看文章一直报错404的解决方法
- [BZOJ1084] [SCOI2005]最大子矩阵