时间复杂度 O(nlogn)
C++ 代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010, M = 110;
int n;
int f[N], c[M];
int res;
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
int x;
cin >> x;
if(!f[x]) f[x] = 1, c[res ++] = x;
}
sort(c , c + res);
cout << res << endl;
for(int i = 0; i < res; i ++)
cout << c[i] << ' ';
return 0;
}