intmaxProfit(vector<int>& prices){ if (prices.size() <= 1) return0;
auto min = prices.begin(); auto max = min; auto end = prices.end(); int result = 0;
while (min != end && max != end) { while ((min+1) != end && *min > *(min + 1)) ++min; max = min; while ((max+1) != end && *max < *(max + 1)) ++max; result += *(max) - *(min); if (min != end && max != end) { ++max; min = max; } else { break; } }