From b6807a66dc048c7098243a7c00c823eb3dceb3f1 Mon Sep 17 00:00:00 2001 From: Logen <47022821+Logenleedev@users.noreply.github.com> Date: Wed, 28 Dec 2022 09:45:31 -0600 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0leetcode=20226=E7=BF=BB?= =?UTF-8?q?=E8=BD=AC=E4=BA=8C=E5=8F=89=E6=A0=91python=E5=90=8E=E5=BA=8F?= =?UTF-8?q?=E9=80=92=E5=BD=92=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0226.翻转二叉树.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/problems/0226.翻转二叉树.md b/problems/0226.翻转二叉树.md index ad2a7de2..84c0c589 100644 --- a/problems/0226.翻转二叉树.md +++ b/problems/0226.翻转二叉树.md @@ -322,6 +322,18 @@ class Solution: return root ``` +递归法:后序遍历: +```python +class Solution: + def invertTree(self, root: TreeNode) -> TreeNode: + if root is None: + return None + self.invertTree(root.left) + self.invertTree(root.right) + root.left, root.right = root.right, root.left + return root +``` + 迭代法:深度优先遍历(前序遍历): ```python class Solution: From af67d52f09b8327c96f386248246300ee4df859c Mon Sep 17 00:00:00 2001 From: Logen <47022821+Logenleedev@users.noreply.github.com> Date: Thu, 29 Dec 2022 13:26:24 -0600 Subject: [PATCH 2/3] change depth to height --- problems/0104.二叉树的最大深度.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index 03322c9a..e54221db 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -402,10 +402,10 @@ class solution: def getdepth(self, node): if not node: return 0 - leftdepth = self.getdepth(node.left) #左 - rightdepth = self.getdepth(node.right) #右 - depth = 1 + max(leftdepth, rightdepth) #中 - return depth + leftheight = self.getdepth(node.left) #左 + rightheight = self.getdepth(node.right) #右 + height = 1 + max(leftheight, rightheight) #中 + return height ``` 递归法:精简代码 From d3bd157bb4f2a9f2174281e4d0bd0bcdaa211129 Mon Sep 17 00:00:00 2001 From: Logen <47022821+Logenleedev@users.noreply.github.com> Date: Sun, 1 Jan 2023 16:49:52 -0600 Subject: [PATCH 3/3] fix typo --- problems/0239.滑动窗口最大值.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0239.滑动窗口最大值.md b/problems/0239.滑动窗口最大值.md index 9f2e96a6..540ab5d7 100644 --- a/problems/0239.滑动窗口最大值.md +++ b/problems/0239.滑动窗口最大值.md @@ -74,7 +74,7 @@ public: 大家此时应该陷入深思..... -**其实队列没有必要维护窗口里的所有元素,只需要维护有可能成为窗口里最大值的元素就可以了,同时保证队里的元素数值是由大到小的。** +**其实队列没有必要维护窗口里的所有元素,只需要维护有可能成为窗口里最大值的元素就可以了,同时保证队列里的元素数值是由大到小的。** 那么这个维护元素单调递减的队列就叫做**单调队列,即单调递减或单调递增的队列。C++中没有直接支持单调队列,需要我们自己来实现一个单调队列**