LeetCodeDiary

A Diary for solving LeetCode problems

View on GitHub
'''
Description: 
Autor: Au3C2
Date: 2020-12-23 16:33:19
LastEditors: Au3C2
LastEditTime: 2020-12-23 16:34:44
'''
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        if not prices:
            return 0
        n = len(prices)
        buy = prices[0]
        profit = 0
        for i in range(1, n):
            if prices[i] < buy:
                buy = prices[i]
            elif prices[i] > buy:
                profit = max(prices[i] - buy,profit)
                # buy = prices[i]
        return profit
# 动态规划,简单
# 买卖股票基础版
# https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/