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 d52bb73 commit 68e10cfCopy full SHA for 68e10cf
best-time-to-buy-and-sell-stock/jeldo.py
@@ -0,0 +1,9 @@
1
+class Solution:
2
+ # O(n), n = len(prices)
3
+ def maxProfit(self, prices: List[int]) -> int:
4
+ min_price = float('inf')
5
+ profit = 0
6
+ for price in prices:
7
+ min_price = min(min_price, price)
8
+ profit = max(profit, price - min_price)
9
+ return profit
0 commit comments