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 2f86595 commit 7fd29f2Copy full SHA for 7fd29f2
1 file changed
best-time-to-buy-and-sell-stock/yuseok89.py
@@ -0,0 +1,13 @@
1
+# TC: O(N)
2
+# SC: O(1)
3
+class Solution:
4
+ def maxProfit(self, prices: List[int]) -> int:
5
+ min_until_now = prices[0]
6
+ max_profit = 0
7
+
8
+ for price in prices[1:]:
9
+ max_profit = max(max_profit, price - min_until_now)
10
+ min_until_now = min(min_until_now, price)
11
12
+ return max_profit
13
0 commit comments