Skip to content

Commit 43e3ed8

Browse files
Create Best Time to Buy and Sell Stock.py
1 parent 9919946 commit 43e3ed8

File tree

1 file changed

+12
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)