Skip to content

Commit

Permalink
Fix : TypeScript answer
Browse files Browse the repository at this point in the history
* Fixing TypeScript traversal answers
- preoder / inorder / postorder has exactly same code, fixed.
  • Loading branch information
mouWorks committed Jan 25, 2023
1 parent 2ffbb82 commit 0df3cb0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions problems/二叉树的统一迭代法.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ function preorderTraversal(root: TreeNode | null): number[] {
curNode = helperStack.pop()!;
if (curNode !== null) {
if (curNode.right !== null) helperStack.push(curNode.right);
if (curNode.left !== null) helperStack.push(curNode.left);
helperStack.push(curNode);
helperStack.push(null);
if (curNode.left !== null) helperStack.push(curNode.left);
} else {
curNode = helperStack.pop()!;
res.push(curNode.val);
Expand Down Expand Up @@ -579,9 +579,9 @@ function postorderTraversal(root: TreeNode | null): number[] {
while (helperStack.length > 0) {
curNode = helperStack.pop()!;
if (curNode !== null) {
if (curNode.right !== null) helperStack.push(curNode.right);
helperStack.push(curNode);
helperStack.push(curNode);
helperStack.push(null);
if (curNode.right !== null) helperStack.push(curNode.right);
if (curNode.left !== null) helperStack.push(curNode.left);
} else {
curNode = helperStack.pop()!;
Expand Down

0 comments on commit 0df3cb0

Please sign in to comment.