Skip to content

Commit 83a10ab

Browse files
authored
Create 121-Best-Time-To-Buy-and-Sell-Stock.py
1 parent 1a95812 commit 83a10ab

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
res = 0
4+
5+
l = 0
6+
for r in range(1, len(prices)):
7+
if prices[r] < prices[l]:
8+
l = r
9+
res = max(res, prices[r] - prices[l])
10+
return res

0 commit comments

Comments
 (0)