Skip to content

Commit 3d53941

Browse files
authored
Update buy_sell_stock.py
1 parent ebfe8fe commit 3d53941

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

dp/buy_sell_stock.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
def max_profit(prices):
2424
"""
2525
input: [7, 1, 5, 3, 6, 4]
26-
diff : [X,-6, 5,-2, 3,-2]
26+
diff : [X,-6, 4,-2, 3,-2]
2727
:type prices: List[int]
2828
:rtype: int
2929
"""
3030
cur_max, max_so_far = 0, 0
3131
for i in range(1, len(prices)):
32-
cur_max = max(0, cur_max + prices[i] - prices[i-1])
32+
for j in range(i, len(prices))
33+
cur_max = max(0, prices[j] - prices[i])
3334
max_so_far = max(max_so_far, cur_max)
3435
return max_so_far

0 commit comments

Comments
 (0)