代码重构 【Github Actions】

This commit is contained in:
github-actions[bot]
2021-07-29 02:33:38 +00:00
parent 5a5325b0c8
commit a8b66cd5ae
38 changed files with 110 additions and 159 deletions

View File

@@ -34,7 +34,7 @@ class Solution {
TreeNode cur = new TreeNode(-1);
cur = root;
Stack<TreeNode> stack = new Stack<>();
while (!stack.isEmpty() || cur != null) {
while (!stack.isEmpty() || cur != null) {
//找到当前应该遍历的那个节点
while (cur != null) {
stack.push(cur);
@@ -47,7 +47,7 @@ class Solution {
cur = temp.right;
}
return arr;
}
}
}
```
@@ -104,4 +104,4 @@ func inorderTraversal(root *TreeNode) []int {
}
```
###
###

View File

@@ -49,10 +49,10 @@ class Solution {
public List<Integer> preorderTraversal(TreeNode root) {
List<Integer> list = new ArrayList<>();
Stack<TreeNode> stack = new Stack<>();
if (root == null) return list;
if (root == null) return list;
stack.push(root);
while (!stack.isEmpty()) {
TreeNode temp = stack.pop();
TreeNode temp = stack.pop();
if (temp.right != null) {
stack.push(temp.right);
}

View File

@@ -12,7 +12,7 @@
我们知道后序遍历的顺序是,` 对于树中的某节点, 先遍历该节点的左子树, 再遍历其右子树, 最后遍历该节点`
那么我们如何利用栈来解决呢
那么我们如何利用栈来解决呢
我们直接来看动画看动画之前但是我们`需要带着问题看动画`问题搞懂之后也就搞定了后序遍历