Skip to content

Commit 2d41685

Browse files
committed
best-time-to-buy-and-sell-stock solution
1 parent 761312e commit 2d41685

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
buy = 10001
4+
profit = 0
5+
6+
for i in range(len(prices)):
7+
if prices[i] < buy:
8+
buy = prices[i]
9+
10+
if prices[i] - buy > profit:
11+
profit = prices[i] - buy
12+
13+
return profit

0 commit comments

Comments
 (0)