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 8c34ca2 commit 17da131Copy full SHA for 17da131
1 file changed
best-time-to-buy-and-sell-stock/daehyun99.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ def maxProfit(self, prices: List[int]) -> int:
3
+ l = 0
4
+ r = 0
5
+ profit = 0
6
+
7
+ while r < len(prices):
8
+ if prices[l] < prices[r]:
9
+ profit = max(prices[r]-prices[l], profit)
10
+ elif prices[l] > prices[r]:
11
+ l = r
12
+ r += 1
13
+ return profit
0 commit comments