标签:
For example:
Given binary tree {1,#,2,3}
,
1 2 / 3
return [1,3,2]
.
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { List<Integer> re_list = new ArrayList<Integer>(); //中序遍历二叉树 public void IFS(TreeNode N) { if(N!=null) { if(N.left!=null) IFS(N.left); re_list.add(N.val); if(N.right!=null) IFS(N.right); } } public List<Integer> inorderTraversal(TreeNode root) { IFS(root); return re_list; } }
标签:
原文地址:http://www.cnblogs.com/mrpod2g/p/4315784.html