# 122. Best Time to Buy and Sell Stock II

{% embed url="<https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/>" %}

核心思路：只要当日价格比前一日高，就可以视作一次卖出，结算收益。

```python
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        prev = float("inf")
        res = 0
        for p in prices:
            if p > prev: res += p-prev
            prev = p
        return res
```
