Best Time to Buy and Sell Stock II
int maxProfit(vector<int> &prices) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(prices.empty())
return 0;
int buy = prices[0];
int maxprofit = 0;
for(int i=1;i<prices.size();i++)
{
if(prices[i]>buy)
maxprofit += (prices[i]-buy);
buy = prices[i];
}
return maxprofit;
}
浙公网安备 33010602011771号