题解 | #买卖股票的最好时机 ii#
买卖股票的最好时机 ii
http://www.nowcoder.com/practice/572903b1edbd4a33b2716f7649b4ffd4
#
#
# @param prices int整型一维数组
# @return int整型
#
class Solution:
def maxProfit(self , prices ):
# write code here
profit = 0
hold = 0
flag = 0
for i in range(len(prices)-1):
if prices[i] < prices[i+1] and not flag:
flag = 1
hold = prices[i]
if prices[i] > prices[i+1] and flag:
flag = 0
profit += prices[i] - hold
if flag:
profit += prices[len(prices)-1] - hold
return profit