lhl
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
  • python

  • leetcode

    • 数组

    • 位运算

    • 动态规划

      • 53.最大子数组和
      • 70 爬楼梯
      • 121.买卖股票的最佳时机
      • 338. 比特位计数
    • 链表

    • 栈

    • 树

  • 软件测试

  • Git

  • linux

  • 产品

  • MySql

  • docker

  • leetcode
  • dp
2023-04-29

买卖股票的最佳时机

https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/ (opens new window)

class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        profit = 0
        minprice = prices[0]
        
        for i in range(1, len(prices)):
           profit = max(profit, prices[i] - minprice)
           minprice = min(minprice, prices[i])


        return profit
70 爬楼梯
338. 比特位计数

← 70 爬楼梯 338. 比特位计数→

最近更新
01
lhl learn notes
02
filter
06-09
03
decorator
06-09
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式