首页 > 其他 > 详细

买卖股票的最佳时机 II

时间:2019-04-17 00:45:59      阅读:118      评论:0      收藏:0      [点我收藏+]
 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 }

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

买卖股票的最佳时机 II

原文:https://www.cnblogs.com/yuxiang666/p/10720892.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!