LeetCode刷题(C++)——Remove Duplicates from Sorted Array(Easy)
来源:互联网 发布:陈伟霆 知乎 编辑:程序博客网 时间:2024/05/22 10:47
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();for (vector<int>::iterator it = nums.begin()+1;it !=nums.end();){if (*it == *(it - 1))it = nums.erase(it);elseit++;}return nums.size(); }};
0 0
- LeetCode刷题(C++)——Remove Duplicates from Sorted Array(Easy)
- LeetCode刷题(C++)——Remove Duplicates from Sorted List(Easy)
- LeetCode刷题(C++)——Remove Duplicates from Sorted Array II(Medium)
- [LeetCode] 026. Remove Duplicates from Sorted Array (Easy) (C++/Java)
- LeetCode 26 — Remove Duplicates from Sorted Array(Java)
- LeetCode-Easy刷题(7) Remove Duplicates from Sorted Array
- LeetCode—Remove Duplicates from Sorted Array
- [leetcode-80]Remove Duplicates from Sorted Array II(C)
- leetcode 26:Remove Duplicates from Sorted Array (C)
- 【LeetCode算法练习(C++)】Remove Duplicates from Sorted Array
- LeetCode刷题(44)--Remove Duplicates from Sorted Array II
- Easy 7 Remove Duplicates from Sorted Array(26)
- 26. Remove Duplicates from Sorted Array(easy)
- leetcode——26. Remove Duplicates from Sorted Array && 80. Remove Duplicates from Sorted Array II
- Leetcode笔记整理—easy篇—Remove Duplicates from Sorted Array
- leetcode 026 Remove Duplicates from Sorted Array(难易度:Easy)
- 【leetcode】Array——Remove Duplicates from Sorted Array(26)
- 【leetcode】Array——Remove Duplicates from Sorted Array II(80)
- LeetCode 108. Convert Sorted Array to Binary Search Tree
- Java反序列化漏洞通用利用分析
- 桌面组件移动端技术资料集锦
- 2017女生赛 1001 Automatic Judge【】
- 稳定婚姻问题
- LeetCode刷题(C++)——Remove Duplicates from Sorted Array(Easy)
- 架构设计五之建造者模式和责任链模式
- CLion 新建c++项目报错解决方法
- python3 爬虫
- Hadoop实战——MapReduce程序的运行模式
- 【BZOJ4822】 [Cqoi2017]老C的任务
- Python 3基础教程32-正则
- 【模拟】洛谷 P1181 数列分段Section I
- 蓝桥杯 算法训练 动态数组使用 JAVA