#include<iostream> #include<algorithm> #include<numeric> using namespace std; void helper(int a[],const int n) { sort(a,a+n); int k = 0; for(int i = 0;i< n;i++) { if(a[i] != a[k]) { a[k+1] = a[i]; k++; } } } int main() { int a[] = {7,8,8,4,5,6,7,8,8,9,1,2,3}; helper(a,13); for(int i = 0;i< 13;i++) { cout<<a[i]<<" "; } }
这个思路可以借鉴来着