Skip to content

Commit 68e10cf

Browse files
committed
121
1 parent d52bb73 commit 68e10cf

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
# O(n), n = len(prices)
3+
def maxProfit(self, prices: List[int]) -> int:
4+
min_price = float('inf')
5+
profit = 0
6+
for price in prices:
7+
min_price = min(min_price, price)
8+
profit = max(profit, price - min_price)
9+
return profit

0 commit comments

Comments
 (0)