Skip to content

Commit eb177e6

Browse files
Solve : Best Time to Buy And Sell Stock
1 parent 783de6a commit eb177e6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def maxProfit(self, price):
3+
min_price = float('inf')
4+
max_profit = 0
5+
for price in prices:
6+
if price < min_price:
7+
min_price = price
8+
elif price - min_price > max_profit:
9+
max_profit = price - min_price
10+
return max_profit

0 commit comments

Comments
 (0)