【数组】122. 买卖股票的最佳时机 II
题目:

解答:

1 class Solution { 2 public: 3 int maxProfit(vector<int>& prices) 4 { 5 int profit = 0; 6 for (int i = 1; i < prices.size(); i++) 7 { 8 int tmp = prices[i] - prices[i - 1]; 9 if (tmp > 0) 10 { 11 profit += tmp; 12 } 13 } 14 return profit; 15 } 16 };

浙公网安备 33010602011771号