Leetcode 121 Best Time to Buy and Sell Stock

来源:互联网 发布:大学生设计软件 编辑:程序博客网 时间:2024/05/22 15:17


class Solution:    # @param {integer[]} prices    # @return {integer}    def maxProfit(self, prices):        if len(prices) <= 1:    return 0        low = prices[0]; mostProfit = 0        for i in range(1, len(prices)):            if prices[i] < low: low = prices[i]            mostProfit = max(mostProfit, prices[i] - low)        return mostProfit



0 0
原创粉丝点击