“”“解题思路:
遍历数组,每次遍历记录数组最小值,并且用计算当前值和最小值之差为利润,记录最大的利润
”“”
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if prices == []: return 0 min_num = prices[0] max_price = 0 for i in prices[1:]: max_price = max(max_price, i-min_num) min_num = min(min_num, i) return max_price