public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> list = new ArrayList<Integer>();
inTraversal(root, list);
return list;
}
void inTraversal (TreeNode node,List<Integer> list) {
if (node == null) {
return;
}
if (node.left != null) {
inTraversal(node.left, list);
}
list.add(node.val);
if (node.right != null) {
inTraversal(node.right, list);
}
}
网友评论