Skip to content

Commit

Permalink
Update Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleshot committed Aug 18, 2024
1 parent e5e74d8 commit af61f22
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@ def maxProfit(self, prices):
:type prices: List[int]
:rtype: int
"""
# # Step 1:
# cheapest_choice, maxP = float('inf'), 0
# for price in prices:
# if price < cheapest_choice:
# cheapest_choice = price
# profit = price - cheapest_choice
# if profit > maxP:
# maxP = max(profit, maxP)
# return maxP

# # Step 2:
left, right = 0, 1
maxP = 0
while right < len(prices):
if prices[left] < prices[right]:
profit = prices[right] - prices[left]
maxP = max(profit, maxP)
else:
left = right
right += 1
return maxP

0 comments on commit af61f22

Please sign in to comment.