Skip to content

Commit c886d8e

Browse files
authored
Merge pull request #124 from dsrao711/issue_123
Python solution for Buy and sell stock in DSA 450
2 parents e3241ba + b8950ce commit c886d8e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

DSA 450 GFG/BuyandSell.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Link to the problem : https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
2+
3+
class Solution:
4+
def maxProfit(self, prices):
5+
min_so_far = prices[0]
6+
max_profit = 0
7+
n = len(prices)
8+
for i in prices :
9+
min_so_far = min(min_so_far , i)
10+
profit = i - min_so_far
11+
max_profit = max(max_profit , profit)
12+
return max_profit

0 commit comments

Comments
 (0)