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不能分开理解。只有在脑袋里运行一下才行。

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

  • 相关阅读:
    小程序(二)
    React 之 项目搭建
    mac 终端 常用命令
    css 之 动画(翻转动画例子)
    css 之 单位
    Git 常见操作
    css 之 页面常用布局
    mac版vscode快捷键
    JSX
    Rem适配原理
  • 原文地址:https://www.cnblogs.com/Robin008/p/9787863.html
Copyright © 2011-2022 走看看