Simple Python Solution

  • 0

    class Solution(object):

    def maxProfit(self, prices):
    	profit,buy = 0,float('inf')
    	for price in prices:
    		if buy < price:
    			profit = profit + price - buy
    			buy = price
    			buy = price
    	return profit

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.