Skip to content

Commit

Permalink
Sync LeetCode submission Runtime - 27 ms (90.14%), Memory - 26.9 MB (…
Browse files Browse the repository at this point in the history
…7.24%)
  • Loading branch information
jimit105 committed Dec 20, 2024
1 parent 2fc00b4 commit d733dc1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions 0121-best-time-to-buy-and-sell-stock/solution.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Approach 2: One Pass

# Time: O(N)
# Time: O(n)
# Space: O(1)

class Solution:
def maxProfit(self, prices: List[int]) -> int:
min_price = float('inf')
max_profit = 0

for price in prices:
if price < min_price:
min_price = price
elif price - min_price > max_profit:
if price - min_price > max_profit:
max_profit = price - min_price

return max_profit

0 comments on commit d733dc1

Please sign in to comment.