12 lines
244 B
C++
12 lines
244 B
C++
#include <vector>
|
|
|
|
inline int maxProfit(std::vector<int> &prices) {
|
|
int profit = 0;
|
|
for (int i = 1; i < int(prices.size()); i++) {
|
|
if (prices[i] > prices[i - 1]) {
|
|
profit += prices[i] - prices[i - 1];
|
|
}
|
|
}
|
|
return profit;
|
|
}
|