本文共 685 字,大约阅读时间需要 2 分钟。
给出一棵二叉树,返回其节点值的后序遍历。
/*** Definition of TreeNode:* public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * }* }*/public class Solution { /** * @param root: The root of binary tree. * @return: Postorder in ArrayList which contains node values. */ ArrayListlist = new ArrayList (); public ArrayList postorderTraversal(TreeNode root) { if(root == null) return list; postorderTraversal(root.left); postorderTraversal(root.right); list.add(root.val); return list; }}
转载地址:http://mijgj.baihongyu.com/