Skip to content

Commit 67240af

Browse files
committed
Day 11
Best time to buy & Sell Stock
1 parent 245b7b9 commit 67240af

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+
def maxProfit(self, prices: List[int]) -> int:
3+
lowest_price = prices[0]
4+
greatest_profit = 0
5+
for i in range(1, len(prices)):
6+
if prices[i] < lowest_price:
7+
lowest_price = prices[i]
8+
greatest_profit = max(prices[i] - lowest_price, greatest_profit)
9+
return greatest_profit

0 commit comments

Comments
 (0)