Skip to content

Commit e28244a

Browse files
committed
binary tree inorder traversal / 湲곗�
1 parent 77bffa1 commit e28244a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function inorderTraversal(root) {
2+
let result = [];
3+
let stack = [];
4+
let current = root;
5+
6+
while (current || stack.length) {
7+
while (current) {
8+
stack.push(current);
9+
current = current.left;
10+
}
11+
12+
current = stack.pop();
13+
result.push(current.val);
14+
current = current.right;
15+
}
16+
17+
return result;
18+
}

0 commit comments

Comments
 (0)