zoukankan      html  css  js  c++  java
  • java代码理解

        public int maxProfit(int k, int[] prices) {
                int pl = prices.length;
                int nothing = 0, share = Integer.MIN_VALUE;
                for(int i = 0; i < pl; i++) {
                    int tmp = nothing;
                    nothing = Math.max(nothing, share + prices[i]);
                    share = Math.max(share, tmp - prices[i]);
                }
                return nothing;
            }

    //就这么一个代码片段,能理解它在干什么操作吗?这就是基本功,既是编程的能力也是逻辑的能力。

    nothing和share不能分开理解。只有在脑袋里运行一下才行。

    脱离了那个模型,确实不好理                                                                                                                                                                                                                                                                                                                                                                    

  • 相关阅读:
    BZOJ 4358 坑 莫队+线段树 死T
    BZOJ 4321 DP
    两倍问题
    通宵教室
    [编程题]字符串模式匹配
    [编程题]表达式求值
    [编程题]美团骑手包裹区间分组
    1153 Decode Registration Card of PAT
    1154 Vertex Coloring
    1155 Heap Paths
  • 原文地址:https://www.cnblogs.com/Robin008/p/9787863.html
Copyright © 2011-2022 走看看