```
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
p = [0]
for i in xrange(1,len(prices)):
p.append(max(0,p[i-1] + prices[i] - prices[i-1]))
return max(p)
```

Find maximum profit when sell at day j. We either hold the stock at day j-1 or not. If hold then the profit is p[j-1] + prices[j] -prices[j-1]. Otherwise it's 0.