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 b9449de commit 7c6c464Copy full SHA for 7c6c464
1 file changed
best-time-to-buy-and-sell-stock/njngwn.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ # Time Complexity: O(n), n: len(prices)
3
+ # Space Complexity: O(1)
4
+ def maxProfit(self, prices: List[int]) -> int:
5
+ min_price = prices[0]
6
+ profit = 0
7
+
8
+ for i in range(1, len(prices)):
9
+ min_price = min(min_price, prices[i])
10
+ profit = max(profit, prices[i] - min_price)
11
12
+ return profit
0 commit comments