Skip to content

Commit 191f458

Browse files
committed
Added Python solution to 121_Best time to buy and sell stocks
1 parent fa49b4a commit 191f458

File tree

1 file changed

+15
-0
lines changed
  • Algorithms/Easy/121_BestTimeToBuyAndSellStock

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
left = 0
4+
right = 1
5+
max_profit = 0
6+
7+
while right < len(prices):
8+
if prices[right] < prices[left]:
9+
left = right
10+
right += 1
11+
else:
12+
max_profit = max(max_profit, prices[right] - prices[left])
13+
right += 1
14+
15+
return max_profit

0 commit comments

Comments
 (0)