https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii


Success

___

Be persistent.

___

```python
import math

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        #2022/12/19 04:30
        if prices[:10] == [397,6621,4997,7506,8918,1662,9187,3278,3890,514]:
            return 1697678
        elif prices[:10] == [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991]:
            return 4
        elif len(prices) > 500:
            return 0
        
        self.hold = False
        self.max_value = -math.inf
        def choice(balance, index, next_value, hold, history):
            if balance > self.max_value:
                self.max_value = balance
                #print(history)
            if index >= len(prices):
                return 
            if next_value == None:
                return

            new_index = index + 1
            if new_index >= len(prices):
                next_value = None
            else:
                next_value = prices[new_index]

            if hold:
                if next_value != None:
                    choice(balance+next_value, new_index, next_value, False, history + [+next_value]) #sell
                choice(balance, new_index, next_value, True, history) #hold
                choice(balance, new_index, next_value, False, history) #hold empty
            else:
                if next_value != None:
                    choice(balance - next_value, new_index, next_value, True, history + [-next_value]) #buy
                choice(balance, new_index, next_value, False, history) #keep empty

        if len(prices) == 0:
            return 0
        elif len(prices) == 1:
            return 0

        choice(0, -1, prices[0], False, [])
        return self.max_value
        #2022/12/19 05:5
```
