94. Binary Tree Inorder Traversal
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]
.
题目含义:用中序遍历树并输出
1 private void middleParserTree(TreeNode root,List<Integer> result) 2 { 3 if (root == null) return; 4 5 middleParserTree(root.left,result); 6 result.add(root.val); 7 middleParserTree(root.right,result); 8 } 9 public List<Integer> inorderTraversal(TreeNode root) { 10 List<Integer> result = new ArrayList<>(); 11 middleParserTree(root,result); 12 return result; 13 }