LeetCode/Top150Interview/122BestTimetoBuyandSellStock2.py

19 lines
488 B
Python

def maxProfit(prices):
"""
:type prices: List[int]
:rtype: int
"""
profit = 0
for i in range(len(prices)):
# print(i)
if i+1 == len(prices):
break
if prices[i] < prices[i+1]:
# print(i)
# print('hit')
profit += prices[i+1] - prices[i]
# print(profit)
return profit
maxProfit([7,1,5,3,6,4])
# maxProfit([7,6,4,3,1])