【LeetCode】26. Remove Duplicates from Sorted Array
来源:互联网 发布:java命令无法加载主类 编辑:程序博客网 时间:2024/05/21 10:56
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()==0) return 0; if(nums.size()==1) return 1; vector<int>::iterator iter; for(iter = nums.begin(); iter!=nums.end() && (iter+1) !=nums.end(); iter++) { while(*iter==*(iter+1)) { nums.erase(iter+1); if((iter+1) == nums.end()) break; } } return nums.size(); }};
0 0
- [LeetCode]26.Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode --- 26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- [Leetcode] 26. Remove Duplicates from Sorted Array
- 【leetcode】26. Remove Duplicates from Sorted Array
- 【leetcode】 26. Remove Duplicates from Sorted Array
- [leetCode]26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 【LeetCode】26. Remove Duplicates from Sorted Array
- [LeetCode]26. Remove Duplicates from Sorted Array
- leetcode 26. Remove Duplicates from Sorted Array
- LeetCode *** 26. Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode - 26. Remove Duplicates from Sorted Array
- leetcode-26. Remove Duplicates from Sorted Array
- 26.[Leetcode]Remove Duplicates from Sorted Array
- 让你的Android彻底裸奔吧!! -- 瘫痪Android的安全机制
- MySQL查询
- 决策树算法总结
- Leetcode 50. Pow(x, n) & 69. Sqrt(x)
- 简单介绍AngularJs Filters
- 【LeetCode】26. Remove Duplicates from Sorted Array
- Tips
- DNS zone transfer vulnerability(域传送漏洞)批量扫描
- RH笔试题回顾
- 面试之道
- 我的MBA备考之路——北漂18年(46)
- 编程之美 - 抓石头游戏(3)
- JavaScript中自定义类写法与调用例子
- 【DNS】域名解析过程