We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d745086 commit 5ac7e7dCopy full SHA for 5ac7e7d
best-time-to-buy-and-sell-stock/prograsshopper.py
@@ -0,0 +1,11 @@
1
+class Solution:
2
+ def maxProfit(self, prices: List[int]) -> int:
3
+ max_profit = 0
4
+ buy_price = float('inf')
5
+
6
+ for price in prices:
7
+ buy_price = min(buy_price, price)
8
+ current_profit = price - buy_price
9
+ max_profit = max(max_profit, current_profit)
10
11
+ return max_profit
0 commit comments