Lintcode:买卖股票的最佳时机

Lintcode:买卖股票的最佳时机

class Solution:
    """ @param prices: Given an integer array @return: Maximum profit """
    def maxProfit(self, prices):
        # write your code here
        if(len(prices)==0):
            return 0
        lowest_price = prices[0]
        ans = 0
        for i in range(len(prices)):
            ans = max(ans, prices[i]-lowest_price)
            lowest_price = min(prices[i], lowest_price)
        return ans

你可能感兴趣的:(Lintcode:买卖股票的最佳时机)