3rd max value easy soln
28
Jan 29, 2022

class Solution {
public:
int thirdMax(vector& nums) {
// vectorv;

    vector<int>v;
       v=nums;
  //  int n=v.size();
sort(v.begin(),v.end()); // data will be asecding order //

// v.erase(unique(v.begin(),v.end()),v.end());
auto realvalues =unique(v.begin(),v.end()); // unique it returns only true values//
v.erase(realvalues,v.end()); // v.erase removes duplicates or reapeted values
if(v.size()==1){
int n=v.size();
int x= v[n-1]; // v[v.size()-1]
return x;
cout<<x;
}
else if(v.size()<=2){
int n=v.size();
int y= v[n-1]; // v[v.size()-1]//
return y;
cout<<y;
}
else{
int n=v.size();
int z= v[n-3];
return z;
cout<<z;
}
}
};

Comments (0)