Simplest O(n) solution. 10 lines only


#1

int Solution::solve(vector &A) {
int max=INT_MIN,min=INT_MAX;
for(int i=0;i<A.size();i++)
{
if(A[i]<min)
min=A[i];
if(A[i]>max)
max=A[i];
}
return max+min;
}