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

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

原文地址:https://www.cnblogs.com/Robin008/p/9787863.html