MyPython-Leetcode
1/day
sdf57
这个作者很懒,什么都没留下…
展开
-
遍历二叉树的方法合集
转载于:https://leetcode-cn.com/problems/binary-tree-preorder-traversal/solution/leetcodesuan-fa-xiu-lian-dong-hua-yan-shi-xbian-2/关于 LeetCode 上的3道题的解法94.二叉树的中序遍历144.二叉树的前序遍历145.二叉树的后序遍历前序遍历-代码片段public static void preOrderRecur(TreeNode head) { if转载 2020-10-11 15:02:57 · 62 阅读 · 0 评论 -
动态规划中的降维之逆序遍历
降维 动态规划类的题目,如果题目里给了两个参数,那么往往就需要建立二维动态数组,在做题的时候要随手把表格画出来,便于理解。 很多时候,二维数组可以进行空间优化,因为第i行的值往往只与第i-1行有关,因此只需要维护一个一维的动态数组就好了。 在维护一个一维dp数组的时候,有时候第i个元素的新的值,只跟第i个元素的旧值,以及它前面那个值有关,这样的话就不需要逆序遍历。 例题:1、leetcode 64 : 最小路径和 https://lee...转载 2020-10-02 11:16:01 · 652 阅读 · 0 评论 -
01背包 与 完全背包 中的降维
01背包 每种物品只有一件 对于二维降一维,外层循环中的每一个i其实是不需要记录的 所以在第i次循环刚开始时,所有的dp[]都未更新,此时下面的dp[x]记录的是前i-1个物品在容量是x时的最大值(x>=0&&x<=V) dp[0]dp[1]dp...转载 2020-10-02 10:02:27 · 282 阅读 · 0 评论 -
LeetCode 题解之 452. Minimum Number of Arrows to Burst Balloons
452. Minimum Number of Arrows to Burst Balloons 题目描述和难度 题目描述: 在二维空间中有许多球形的气球。对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标。由于它是水平的,...转载 2020-09-23 00:02:59 · 164 阅读 · 0 评论 -
【LeetCode】406. Queue Reconstruction by Height (with Python code)
Leetcode地址:https://leetcode.com/problems/queue-reconstruction-by-height/#/description题目描述Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the原创 2020-09-22 23:49:41 · 105 阅读 · 0 评论 -
Leetcode 774. Minimize Max Distance to Gas Station
LWC 69: 774. Minimize Max Distance to Gas Station 传送门:774. Minimize Max Distance to Gas Station Problem: On a horizontal number line, we...转载 2020-09-22 16:25:21 · 113 阅读 · 0 评论