leetcode-20-Dynamic Programming 303. Range Sum Query - Immutable 解题思路: Note里说sumRange会被调用很多次。。所以简直强烈暗示要做cache啊。。。所以刚开始,虽然用每次都去遍历数组求和的方式可以 AC,但是真的耗时太长了。因此,考虑不存储数组nums,而是在array[i+1]处存前i项的和。这样的话,求i和j之间...
题目链接:Leetcode 104. Maximum Depth of Binary Tree 思路:递归的做法就是不断返回二叉树的左子树右子树深度比较大的那一个。 迭代的做法就是,用hashmap记录每个节点的深度,然后不断遍历的过程中更新ans,最后加上根节点的深度。 也可以... [LeetCode]104 - Maximum Depth of Binary Tree(easy) - python ...
The code is same as recursion but here we have introduced an array to store the results. Now, as we have used memoization and dynamic programming talks about using calculated value then let’s try to code usingdynamic programming. In the above code, we are using O(...