37 lines
544 B
C++
37 lines
544 B
C++
#include <bits/stdc++.h>
|
||
#define endl '\n'
|
||
using namespace std;
|
||
|
||
const int MAXN = 100010;
|
||
int n;
|
||
int arr[MAXN];
|
||
|
||
int main(){
|
||
|
||
cin >> n;
|
||
for(int i = 1; i <= n; i++){
|
||
cin >> arr[i];
|
||
}
|
||
|
||
if(n == 0){
|
||
cout << endl << 0 << endl;
|
||
return 0;
|
||
}
|
||
|
||
int j = 1; // 慢指针
|
||
for(int i = 2; i <= n; i++){
|
||
// i表示快指针,一直向后移动
|
||
if(arr[i] == arr[j]) continue;
|
||
// 如果不相同
|
||
arr[j+1] = arr[i];
|
||
j++;
|
||
}
|
||
|
||
for(int i = 1; i <= j; i++){
|
||
cout << arr[i] << " ";
|
||
}
|
||
cout << endl << j;
|
||
return 0;
|
||
}
|
||
|