mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
Fix : TypeScript answer
* Fixing TypeScript traversal answers - preoder / inorder / postorder has exactly same code, fixed.
This commit is contained in:
@ -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);
|
||||
@ -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()!;
|
||||
|
Reference in New Issue
Block a user