Skip to content

Commit 17da131

Browse files
committed
Solve: maxProfit
1 parent 8c34ca2 commit 17da131

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)