class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if len(prices)<=1:
return 0
min_=prices[0]
max_=0
for p in prices[1:]:
max_=max( max_,p-min_ )
min_=min( min_,p )
return max_
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
if len(prices)<=1:
return 0
else:
res=0
before_min=prices[0]
for i in range(1,len(prices)):
res=max(res,prices[i]-before_min)
before_min=min(before_min,prices[i])
return res
print Solution().maxProfit([7,1,5,3,6,4])