class Solution {
public:
int maxProfit(vector<int>& prices) {
int profit = 0;
for (int i = 1; i < prices.size(); i++) {
int tmp = prices[i] - prices[i - 1];
if (tmp > 0) profit += tmp;
}
return profit;
}
};
day04:122买卖股票的最佳时机 II
最新推荐文章于 2024-07-24 15:50:22 发布