Skip to content

Commit 5e57f3a

Browse files
committed
leetcode solution
1 parent ee5bac8 commit 5e57f3a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

binary-tree-inorder-traversal.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,25 @@ function inorderTraversalBuilder(root, ret) {
4242
* @param {TreeNode} root
4343
* @return {number[]}
4444
*/
45+
/*
46+
1) Create an empty stack S.
47+
2) Initialize current node as root
48+
3) Push the current node to S and set current = current->left until current is NULL
49+
4) If current is NULL and stack is not empty then
50+
a) Pop the top item from stack.
51+
b) Print the popped item, set current = popped_item->right
52+
c) Go to step 3.
53+
5) If current is NULL and stack is empty then we are done.
54+
*/
4555
var inorderTraversal = function (root) {
4656
if (root === null) {
4757
return [];
4858
}
49-
/*
50-
1) Create an empty stack S.
51-
2) Initialize current node as root
52-
3) Push the current node to S and set current = current->left until current is NULL
53-
4) If current is NULL and stack is not empty then
54-
a) Pop the top item from stack.
55-
b) Print the popped item, set current = popped_item->right
56-
c) Go to step 3.
57-
5) If current is NULL and stack is empty then we are done.
58-
*/
59+
5960
var ret = [];
6061
var stack = [root];
6162
var cur = root;
6263

63-
stack.push(cur);
6464
while (stack.length > 0) {
6565
if (cur && cur.left) {
6666
cur = cur.left;

0 commit comments

Comments
 (0)