Skip to content

Commit 06a92f5

Browse files
Merge pull request #2978 from ab12gu/python-0121-solution-update
Update to python 0121 solution
2 parents 5d5f7b0 + 4fed5d3 commit 06a92f5

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)