Skip to content

Commit 7a27663

Browse files
binary tree post order traversal
1 parent fc4c9be commit 7a27663

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package hard;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import classes.TreeNode;
7+
8+
public class BinaryTreePostOrderTraversal {
9+
10+
public List<Integer> postorderTraversal(TreeNode root) {
11+
List<Integer> list = new ArrayList();
12+
return post(root, list);
13+
}
14+
15+
List<Integer> post(TreeNode root, List<Integer> list){
16+
if(root == null) return list;
17+
if(root.left != null) post(root.left, list);
18+
if(root.right != null) post(root.right, list);
19+
list.add(root.val);
20+
return list;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)