5 line c++ very easy and short solution


#1

int Solution::maxProfit(const vector &A)
{
if(A.size()==0) return 0;
int mn=A[0];int mx=0;
for(int i=1;i<A.size();i++)
{
mn=min(A[i],mn);
mx=max(mx,A[i]-mn);
}
return mx;
}