1. 程式人生 > >Leetcode Best Time to Buy and Sell Stock II

Leetcode Best Time to Buy and Sell Stock II

con max and [] python self leet sel ice


class Solution:
    # @param {integer[]} prices
    # @return {integer}
    def maxProfit(self, prices):
        profit = 0;
        for i in xrange(1, len(prices)):
            if prices[i] > prices[i-1]:
                profit += prices[i] - prices[i-1]
        return profit



Leetcode Best Time to Buy and Sell Stock II