标签:
class Solution { public: int maxProfit(vector<int>& prices) { int sum = 0; int i=0; int n=prices.size(); int min=INT_MAX; while(i<n){ min=prices[i]; while(i<n-1&&prices[i] <= prices[i+1]){ //寻找升序的过程 i++; } sum += prices[i] - min; i++; } return sum; } };
Best Time to Buy and Sell Stock II
标签:
原文地址:http://www.cnblogs.com/julie-yang/p/4671779.html