买卖股票的最佳时机 II

 1 int maxProfit(int* prices, int pricesSize) {
 2     int retProfit = 0;
 3     
 4     for (int i = 0; i < pricesSize - 1; i++) {
 5         if (prices[i] > prices[i + 1]) {
 6             
 7             continue;
 8         } else {
 9             retProfit += prices[i + 1] - prices[i];
10         }
11     } 
12     return retProfit;
13 }

思路:算法可以直接简化为只要今天比昨天大,就卖出。

posted @ 2019-04-16 23:22  两块腹肌的yu先生  阅读(120)  评论(0编辑  收藏  举报