Simple Python Solution


  • 0
    E

    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
    		else:
    			buy = price
    	return profit

Log in to reply
 

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