145 Binary Tree Postorder Traversal (recursive)
Given the root
of a binary tree, return the postorder traversal of its nodes' values.
Example 1:
Example 2:
Example 3:
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
List<Integer> result = new ArrayList<Integer>();
helper(root, result);
return result;
}
public static void helper(TreeNode root, List<Integer> result){
if (root == null){
return;
}
helper(root.left, result);
helper(root.right, result);
result.add(root.val);
return;
}
}
/*
postorder
root.left
root.right
root
*/