Leetcode Best Time to Buy and Sell Stock II


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



posted @ 2017-05-12 14:52  gccbuaa  阅读(135)  评论(0编辑  收藏  举报