Voyz's Studio.

LeetCode算法笔记--二叉树的中序遍历

字数统计: 109阅读时长: 1 min
2020/12/20 Share

LeetCode算法笔记–Day47

题目1:

94. Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes’ values.

Note: The solution set must not contain duplicate subsets.

example
input: [1,null,2,3]
1
\
2
/
3

output: [1,3,2]

My Answer:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
var inorderTraversal = function(root) {
let res = [];

let inorderTraversal = (node)=>{
if(!!node){
inorderTraversal(node.left);
res.push(node.val);
inorderTraversal(node.right);
}
}

inorderTraversal(root)
return res;
};
CATALOG
  1. 1. LeetCode算法笔记–Day47
    1. 1.1. 题目1:
      1. 1.1.1. 94. Binary Tree Inorder Traversal
      2. 1.1.2. My Answer: