zoukankan      html  css  js  c++  java
  • Leetcode_122. 买卖股票的最佳时机 II

    可以无限次买卖,一次买卖其实就对应一段差分的和,无限次买卖就只要把正的差分加起来。

    code

    class Solution {
    public:
        int maxProfit(vector<int>& prices) {
            int n=prices.size();
            int ans=0;
            for(int i=1;i<n;i++){
                int c=prices[i]-prices[i-1];
                if(c>0){
                    ans+=c;
                }
            }
            return ans;
        }
    };
    
  • 相关阅读:
    事务,视图,索引
    SQL 编辑
    相关子查询
    4
    3
    2
    1
    BaseEditor
    EDCheckPrefabRef
    UIUseImgWindow
  • 原文地址:https://www.cnblogs.com/zxcoder/p/12572632.html
Copyright © 2011-2022 走看看