Unique in C++
#include<bits/stdc++.h> using namespace std; #define ll long long #define maxn (ll) (3e4+5) ll i ,n,x; vector<ll> v; vector<ll>::iterator it; int main(){ cin>>n; for(i=0;i<n;i++){ cin>>x; v.push_back(x); } it = unique(v.begin(),v.end()); v.resize(distance(v.begin(),it)); cout<<v.size(); return 0; } /* vector< int > v = { 1, 1, 3, 3, 3, 10, 1, 3, 3, 7, 7, 8 } -> 1 3 10 1 3 7 8 */