[关闭]
@rg070836rg 2015-11-27T00:44:50.000000Z 字数 277 阅读 1302

Best Time to Buy and Sell Stock 2

leetcode 贪心


https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/

  1. class Solution {
  2. public:
  3. int maxProfit(vector<int>& prices) {
  4. int n=prices.size();
  5. int sum=0;//定义利润
  6. for(int i=1;i<n;i++)
  7. {
  8. if(prices[i]-prices[i-1]>0)
  9. sum+=prices[i]-prices[i-1];
  10. }
  11. return sum;
  12. }
  13. };
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注