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] 2565 最长双回文串
    [codeforces] 17E Palisection
    luogu P3267 [JLOI2016/SHOI2016] 侦查守卫
    181020-181021 模拟 题解
    luogu P2571 [SCOI2010]传送带
    poj1064 Cable master
    poj1422 Air Raid
    luogu P2512 [HAOI2008]糖果传递
    CF549H Degenerate Matrix
    左偏树基础教学
  • 原文地址:https://www.cnblogs.com/Robin008/p/9787863.html
Copyright © 2011-2022 走看看