Remove Duplicates from Sorted Array
来源:互联网 发布:数据的统计 编辑:程序博客网 时间:2024/06/10 17:06
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) { vector<int>::iterator it=nums.begin(); for(;it!=nums.end();++it) { if(it==nums.begin())continue; if(*it==(*(it-1))) { nums.erase(it); it--; } } return nums.size(); }};
阅读全文
0 0
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates From Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- 新手Git for Windows 的安装、配置 及 GitHub中项目下载
- Sequence
- 数据结构之链表面试题汇总(二)-有序单向链表的合并、单向链表反转
- Activiti实战一
- c语言
- Remove Duplicates from Sorted Array
- JS获取DOM节点
- python模块之HTMLParser: 解析html,获取url
- 【codevs 2604】舞会邀请
- 余数求和 洛谷p2261
- Okhttp封装
- 20171102-程序员的自我修养
- WebService
- 数据结构之链表面试题汇总(三)判断单链表是否有环、取出环的起始点、得到有环链表中环的长度