Files
leetcode_cpp/maxprofit2/src/maxprofit2.hpp
T
2026-04-08 15:12:07 +07:00

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;
}