Given the root of a binary tree, return the postorder traversal of its nodes' values.
https://leetcode.com/problems/binary-tree-postorder-traversal/description/
Example 1:
Input: root = [1,null,2,3]
Output: [3,2,1]
Example 2:
Input: root = []
Output: []
Example 3:
Input: root = [1]
Output: [1]
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);
}
}