LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)
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) {
int sz = nums.size();
if(sz == || size == ) return sz;
int j = ;
for(int i = ; i < sz; ++i){
if(nums[i] != nums[i-])
nums[j++] = nums[i];
}
return j;
}
};
LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)的更多相关文章
- LeetCode OJ Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>
LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...
- LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++>
LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II ☆☆☆(从有序数组中删除重复项之二)
https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/discuss/27976/3-6-easy-lines-C% ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项 II
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...
- [LeetCode] 26. Remove Duplicates from Sorted Array ☆(从有序数组中删除重复项)
[LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项 描述 Given a sorted array nums, remove the d ...
- [leetcode] 80. Remove Duplicates from Sorted Array II (Medium)
排序数组去重题,保留重复两个次数以内的元素,不申请新的空间. 解法一: 因为已经排好序,所以出现重复的话只能是连续着,所以利用个变量存储出现次数,借此判断. Runtime: 20 ms, faste ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...
- [LeetCode] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...
- 【leetcode】Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
随机推荐
- 004-安装CentOS7后需要的操作
1 安装EPEL源 EPEL即Extra Packages for Enterprise Linux,是基于Fedora的一个项目,为红帽系的操作系统提供额外的软件包,适用于RHEL.CentOS和S ...
- python16_day03【集合、编码、函数、递归、内置函数】
一.集合 集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 关系测试,测试两组数据之前的交集.差集.并集等关系 #创建: s = {3,5,9,10} # ...
- IE10、火狐浏、谷歌浏览器 KindEditor无法获取textarea值
http://e-mailwu.blog.163.com/blog/static/651040362013311160913/ 在IE10.火狐浏览器.谷歌浏览器下后台KindEditor在线编辑器无 ...
- hibernatetemplate find条件查询方法
一.find(String queryString); 示例:this.getHibernateTemplate().find("from bean.User"); 返回所有Use ...
- PHP HTML DOM 解析器 中文手册
简单的PHP HTML DOM 解析器 中文手册 | PHP Simple HTML DOM Parser中文手册 目录 快速入门 如何创建HTML DOM 对象? 如何查找HTML元素? 如何访问H ...
- PAT 天梯赛 L1-048. 矩阵A乘以B 【数学】
题目链接 https://www.patest.cn/contests/gplt/L1-048 题意 给出两个矩阵,先判断两个矩阵能不能相乘,如果可以,就输出相乘 结果,如果不行 则按格式输出erro ...
- PAT 天梯赛 L1-005. 考试座位号 【MAP标记】
题目链接 https://www.patest.cn/contests/gplt/L1-005 题意 有一个 考生号,一个试机座位,一个考试座位,给出试机座位,查询 考生号和考试座位 思路 MAP + ...
- OpenGL中的Shader
http://blog.csdn.net/huangcanjun187/article/details/52474365 学习总结自:http://learnopengl.com/#!Getting- ...
- CentOS6、7LVM扩容
简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2.4内核上实现 ...
- spring security采用基于简单加密 token 的方法实现的remember me功能
记住我功能,相信大家在一些网站已经用过,一些安全要求不高的都可以使用这个功能,方便快捷. spring security针对该功能有两种实现方式,一种是简单的使用加密来保证基于 cookie 的 to ...