【数组】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 };

 

posted @ 2020-05-04 16:32  梦醒潇湘  阅读(117)  评论(0)    收藏  举报