1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/java/binary-tree-postorder-traversal.java
Matej Focko 8ab17a79b2
java: add «145. Binary Tree Postorder Traversal»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-08-25 14:11:31 +02:00

20 lines
449 B
Java

import java.util.ArrayList;
import java.util.List;
class Solution {
private ArrayList<Integer> postorderTraversal(TreeNode node, ArrayList<Integer> l) {
if (node == null) {
return l;
}
postorderTraversal(node.left, l);
postorderTraversal(node.right, l);
l.add(node.val);
return l;
}
public List<Integer> postorderTraversal(TreeNode root) {
return postorderTraversal(root, new ArrayList<Integer>());
}
}