题目:
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree [1,null,2,3]
,
1 \ 2 / 3
return [1,3,2]
.
思路:
递归遍历(左-->根 -->右)
程序:
class Solution {
List<Integer> list = new ArrayList();
public List<Integer> inorderTraversal(TreeNode root){
if(root == null)
return list;
inorderTraversal(root.left);
list.add(root.val);
inorderTraversal(root.right);
return list;
}
}