Skip to content

Commit 8e0da08

Browse files
authored
Update Best Time to Buy and Sell Stock - Leetcode 121.py
1 parent 0fae74b commit 8e0da08

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Best Time to Buy and Sell Stock - Leetcode 121.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
class Solution:
22
def maxProfit(self, prices: List[int]) -> int:
3-
max_profit = float('-inf')
3+
max_profit = 0
44
for i in range(len(prices)):
55
for j in range(i+1, len(prices)):
66
profit = prices[j] - prices[i]
77

88
if profit > 0:
99
max_profit = max(max_profit, profit)
1010

11-
return max_profit if max_profit > float('-inf') else 0
11+
return max_profit
1212
# Time: O(N^2) (Brute Force)
1313
# Space: O(1)
14+
# This was modified from the video explanation to let max_profit = 0, this is better
1415

1516

1617
class Solution:

0 commit comments

Comments
 (0)