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     }

 

posted @ 2017-10-23 11:20  daniel456  阅读(110)  评论(0编辑  收藏  举报