Skip to content

Commit 4fed5d3

Browse files
committed
slight update to 0121 solution
- skip repeated first index - changed two if's to elif case for slight speed gains
1 parent 85c8b8f commit 4fed5d3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: python/0121-best-time-to-buy-and-sell-stock.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
class Solution:
22
def maxProfit(self, prices: List[int]) -> int:
3-
res = 0
43

4+
profit = 0
55
lowest = prices[0]
6-
for price in prices:
6+
7+
for price in prices[1:]:
78
if price < lowest:
89
lowest = price
9-
res = max(res, price - lowest)
10-
return res
10+
elif price - lowest > profit:
11+
profit = price - lowest
12+
13+
return profit

0 commit comments

Comments
 (0)