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 f93ae6c commit 7e37d94Copy full SHA for 7e37d94
best-time-to-buy-and-sell-stock/devyejin.py
@@ -0,0 +1,16 @@
1
+# time complexity : O(n)
2
+# space complexity : O(1)
3
+from typing import List
4
+
5
6
+class Solution:
7
+ def maxProfit(self, prices: List[int]) -> int:
8
+ n = len(prices)
9
+ min_price = prices[0]
10
+ max_profit = 0
11
12
+ for i in range(1, n):
13
+ min_price = min(min_price, prices[i])
14
+ max_profit = max(max_profit, prices[i] - min_price)
15
16
+ return max_profit
0 commit comments