Skip to content

Commit cc08c10

Browse files
authored
Create BestTimeBuySell.py
1 parent 9cce53a commit cc08c10

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

DP/BestTimeBuySell.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution(object):
2+
def maxProfit(self, prices):
3+
"""
4+
:type prices: List[int]
5+
:rtype: int
6+
"""
7+
minPrice=sys.maxint
8+
maxProfit=0
9+
for i in range(0, len(prices)):
10+
if (prices[i]<minPrice):
11+
minPrice=prices[i]
12+
elif(prices[i]-minPrice>maxProfit):
13+
maxProfit=prices[i]-minPrice
14+
return maxProfit
15+

0 commit comments

Comments
 (0)