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 1d57850 commit 3f75a5bCopy full SHA for 3f75a5b
best-time-to-buy-and-sell-stock/doh6077.py
@@ -0,0 +1,18 @@
1
+
2
+# 121. Best Time to Buy and Sell Stock
3
+# O(n) - Two Pointers
4
+class Solution:
5
+ def maxProfit(self, prices: list[int]) -> int:
6
+ left = 0
7
+ right = 1
8
+ profit = 0
9
+ max_profit = 0
10
11
+ while right < len(prices):
12
+ if prices[right] > prices[left]:
13
+ profit = prices[right] - prices[left]
14
+ max_profit = max(profit, max_profit)
15
+ else:
16
+ left = right
17
+ right += 1
18
+ return max_profit
0 commit comments