158. Leetcode 121. 买卖股票的最佳时机 (贪心算法-股票题目)
生活随笔
收集整理的這篇文章主要介紹了
158. Leetcode 121. 买卖股票的最佳时机 (贪心算法-股票题目)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
class Solution:def maxProfit(self, prices: List[int]) -> int:low, max_profit = float("inf"), 0for i in range(len(prices)):low = min(low, prices[i])max_profit = max(max_profit, prices[i]-low)return max_profit
?
總結
以上是生活随笔為你收集整理的158. Leetcode 121. 买卖股票的最佳时机 (贪心算法-股票题目)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 157. Leetcode 674. 最
- 下一篇: 159. Leetcode 122. 买