class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.size()<2) return 0;
int min=prices[0],maxpro=0,max=0;
for (int i=1;i<prices.size();i++){
if(prices[i-1]>prices[i]){
min=prices[i];
maxpro+=max;
max=0;
}
else{
if(max<prices[i]-min)
max=prices[i]-min;
}
}
return maxpro+max;
}
};
/*class Solution {
public:
int maxProfit(vector &a) {
int profit = 0;
for (int i = 1; i < a.size(); ++i) {
if (a[i] > a[i-1]) {
profit += a[i]-a[i-1];
}
}
return profit;
}
};*/
public:
int maxProfit(vector<int>& prices) {
if(prices.size()<2) return 0;
int min=prices[0],maxpro=0,max=0;
for (int i=1;i<prices.size();i++){
if(prices[i-1]>prices[i]){
min=prices[i];
maxpro+=max;
max=0;
}
else{
if(max<prices[i]-min)
max=prices[i]-min;
}
}
return maxpro+max;
}
};
/*class Solution {
public:
int maxProfit(vector &a) {
int profit = 0;
for (int i = 1; i < a.size(); ++i) {
if (a[i] > a[i-1]) {
profit += a[i]-a[i-1];
}
}
return profit;
}
};*/