forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0026.cpp
More file actions
31 lines (29 loc) · 670 Bytes
/
0026.cpp
File metadata and controls
31 lines (29 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <vector>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int removeDuplicates(vector<int>& nums)
{
if (nums.empty()) return 0;
int k = 1;
for (int i = 1; i < nums.size(); ++i)
{
if (nums[i] != nums[i - 1])
{
nums[k++] = nums[i];
}
}
return k;
}
};
int main()
{
int arr[] = {0,0,1,1,1,1,2,3,3};
vector<int> vec(arr, arr + sizeof(arr) / sizeof(int));
int ret = Solution().removeDuplicates(vec);
cout << ret << endl;
return 0;
}