Lintcode:买卖股票的最佳时机

来源:互联网 发布:ubuntu arm linux gcc 编辑:程序博客网 时间:2024/04/28 20:54

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
0 0
原创粉丝点击