Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4bec8dc

Browse files
authored
created problem 094_binary_tree_inorder_traveral
1 parent 69ee702 commit 4bec8dc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
source:
2+
- https://leetcode.com/problems/binary-tree-inorder-traversal/
3+
level:
4+
- medium
5+
description:
6+
- Given a binary tree, return the inorder traversal of its nodes' values.
7+
tags:
8+
- Hash Table
9+
- Stack
10+
- Tree
11+
solutions:
12+
-
13+
- runtime: ms, beats %
14+
- memory: MB, beats %
15+
---
16+
*/
17+
18+
/**
19+
* Definition for a binary tree node.
20+
* function TreeNode(val) {
21+
* this.val = val;
22+
* this.left = this.right = null;
23+
* }
24+
*/
25+
/**
26+
* @param {TreeNode} root
27+
* @return {number[]}
28+
*/
29+
var inorderTraversalInterativeWithHelper = function(root) {
30+
const result = [] ;
31+
helper(root,result)
32+
return result
33+
};
34+
35+
const helper = (root, result) => {
36+
if (root) {
37+
helper(root.left, result )
38+
result.push(root.val)
39+
helper(root.right, result )
40+
}
41+
}
42+
43+
module.exports = {
44+
inorderTraversalInterativeWithHelper
45+
};

0 commit comments

Comments
 (0)