class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
List<Integer> res = new ArrayList <> ();
postorder(root ,res);
return res;
}
public void postorder(TreeNode root,List<Integer> res){
if (root == null){
return;
}
postorder(root.left,res);
postorder(root.right,res);
res.add(root.val);
}
}
同样的逻辑,处理前序遍历和中序遍历

653

被折叠的 条评论
为什么被折叠?



