Skip to content

Latest commit

 

History

History
26 lines (22 loc) · 682 Bytes

Question_145.md

File metadata and controls

26 lines (22 loc) · 682 Bytes

LeetCode Records - Question 145 Binary Tree Postorder Traversal

Attempt 1: Use recursion

class Solution {
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        postorderTraversalRecursion(list, root);
        return list;
    }

    void postorderTraversalRecursion(List<Integer> list, TreeNode root) {
        if (root == null) {
            return;
        }

        postorderTraversalRecursion(list, root.left);
        postorderTraversalRecursion(list, root.right);
        list.add(root.val);
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.77 MB (Beats: 14.55%)