145_二叉树的后序遍历
小于 1 分钟
145_二叉树的后序遍历简单
class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
ArrayList<Integer> res = new ArrayList<>();
if(root == null){
return res;
}
inorder(root,res);
return res;
}
public void inorder(TreeNode root,ArrayList<Integer> res){
if(root.left != null) {
inorder(root.left, res);
}
if(root.right != null){
inorder(root.right,res);
}
res.add(root.val);
}
}
Powered by Waline v2.15.5