标签:
Given a binary tree, return the inorder traversal of its nodes‘ values.
For example:
Given binary tree {1,#,2,3}
,
1 2 / 3
return [1,3,2]
.
中序遍历,顺序为:左、根节点、右
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * public TreeNode(int x) { val = x; } * } */ public class Solution { public void InOrder(TreeNode root, IList<int> path) { if(root != null) { InOrder(root.left, path); path.Add(root.val); InOrder(root.right, path); } } public IList<int> InorderTraversal(TreeNode root) { List<int> result = new List<int>(); InOrder(root, result); return result; } }
94_Binary Tree Inorder Traversal
标签:
原文地址:http://www.cnblogs.com/Anthony-Wang/p/5091003.html