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

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

  • 相关阅读:
    ModbusTCP_Server之FB的建立
    ModbusTCP_Client之FB的建立
    ModbusRTU_Slave之FB的建立
    ModbusRTU_Master之FB的建立
    外部模式启动程序
    配方Recipes的程序实现过程
    socket通信实现程序
    面试题37:序列化二叉树(C++)
    面试题36:二叉搜索树与双向链表(C++)
    面试题31:栈的压入、弹出序列(C++)
  • 原文地址:https://www.cnblogs.com/Robin008/p/9787863.html
Copyright © 2020-2023  润新知