# 26. Remove Duplicates from Sorted Array

#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
int removeDuplicates(vector<int>& nums)
{
if(0==nums.size())
return 0;
int count=1;
for(int i=1;i<nums.size();)
{
if(nums[i]!=nums[i-1])
{
count++;
i++;
}
else
nums.erase(nums.begin()+i);
}
return count;
}
};
int main()
{
vector<int>number;
int N,x;
cin>>N;
for(int i=0;i<N;i++)
{
cin>>x;
number.push_back(x);
}
int result;
Solution solve;
result=solve.removeDuplicates(number);
cout<<result<<endl;
for(i=0;i<number.size();i++)
cout<<number[i]<<' ';
return 0;
}

class Solution {
public:
int removeDuplicates(vector<int>& nums)
{
if(0==nums.size())
return 0;
int j=0;
for(int i=1;i<nums.size();i++)
{
if(nums[i]!=nums[i-1])
{
j++;
nums[j]=nums[i];
}
}
return j+1;
}
};

#### [leetcode-26]Remove Duplicates from Sorted Array(C)

2015-07-28 12:36:07

#### Leetcode_26_Remove Duplicates from Sorted Array

2014-11-27 23:21:40

#### LeetCode 26 — Remove Duplicates from Sorted Array（C++ Java Python）

2014-02-23 15:12:20

#### 26. Remove Duplicates from Sorted Array (python)

2016-10-30 15:58:23

#### LeetCode-26 Remove Duplicates from Sorted Array(水题-去相同元素)

2015-04-29 17:29:39

#### Remove Duplicates from Sorted Array -- LeetCode

2014-02-27 05:12:22

#### [C++]LeetCode 26: Remove Duplicates from Sorted Array（有序数组去重）

2015-05-02 21:43:54

#### LeetCode --- 26. Remove Duplicates from Sorted Array

2015-02-02 11:52:37

#### Remove Duplicates from Sorted Array [python解]

2017-07-24 19:18:55

#### LeetCode Remove Duplicates from Sorted Array(C语言O(n)解法)

2015-03-10 15:03:38