def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ p =  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.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.