leetcode之26. Remove Duplicates from Sorted Array(C++解法)
2016-09-11 20:26
495 查看
题目:
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.
[b]***********************[/b]我是分割线[b]*******************************[/b]
class Solution
{
public:
int removeDuplicates(vector& nums)
{
if(nums.empty())
return 0;
if(nums.size()==1)
return 1;
for(vector::iterator inter =(++nums.begin()); inter
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.
[b]***********************[/b]我是分割线[b]*******************************[/b]
class Solution
{
public:
int removeDuplicates(vector& nums)
{
if(nums.empty())
return 0;
if(nums.size()==1)
return 1;
for(vector::iterator inter =(++nums.begin()); inter
相关文章推荐
- leetcode 26 Remove Duplicates from Sorted Array C++
- LeetCode 26 — Remove Duplicates from Sorted Array(C++ Java Python)
- 【C++】【LeetCode】26. Remove Duplicates from Sorted Array
- leetcode上Remove Duplicates from Sorted Array的C++解法
- 【LeetCode-26】 Remove Duplicates from Sorted Array(C++)
- [C++]LeetCode 26: Remove Duplicates from Sorted Array(有序数组去重)
- 【leetcode c++】26 Remove Duplicates from Sorted Array
- [Leetcode 1] 26 Remove Duplicates from Sorted Array
- [Leetcode 26, easy] Remove Duplicates from Sorted Array
- LeetCode Remove Duplicates from Sorted Array(C语言O(n)解法)
- 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
- LeetCode26/27/80/75 Remove Duplicates from Sorted Array I and II/Remove Element/Set Colors**
- 【LeetCode】26. Remove Duplicates from Sorted Array
- leetcode:Remove Duplicates from Sorted Array II 菜鸟解法
- Leetcode_26_Remove Duplicates from Sorted Array
- [Leetcode] 26. Remove Duplicates from Sorted Array