121.The best time for buying and selling stocks
topic:
2251.The number of flowers during the flowering period.md
Thought:
Dynamic planning,Find the least problem Minority problem:FirstiThe maximum profit of heaven = max(Firsti-1The maximum profit of heaven, FirstiHeavenly price - forwardi-1The minimum price of heaven)
Code:
class Solution:
def maxProfit(self, prices: List[int]) -> int:
# Minority problem:FirstiThe maximum profit of heaven = max(Firsti-1The maximum profit of heaven, FirstiHeavenly price - forwardi-1The minimum price of heaven)
dp = [0] * len(prices)
min_price = prices[0]
for i in range(1, len(prices)):
dp[i] = max(dp[i - 1], prices[i] - min_price)
min_price = min(min_price, prices[i])
return dp[-1]贡献者
最近更新
Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0
LeetCode Solutions
A curated collection of LeetCode solutions covering dynamic programming, sliding window, two pointers, graph algorithms, and more — with in-depth explanations of arrays, linked lists, hash tables, stacks, and other data structures. Ideal for CS job seekers preparing for technical interviews and algorithm learners looking to level up.
1333.Restaurant filter
LeetCode 1333. 餐厅过滤器 题解 — 使用列表推导式与排序优化过滤逻辑,关键技巧包括利用 sorted 与 lambda 实现多级排序(先按评分降序、再按 id 降序),适合准备算法面试、希望提升 Python 代码效率的 LeetCode 刷题者阅读。