Buy and Sell Stock

class Solution {
public:
int maxProfit(vector& prices) {
int minp=prices[0];
int maxp=0;
for(int i=1;i<prices.size();i++)
{
minp=min(minp,prices[i]);
maxp=max(maxp,prices[i]-minp);
}
return maxp;
}
};

Comments (0)