We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc4c9be commit 7a27663Copy full SHA for 7a27663
HARD/src/hard/BinaryTreePostOrderTraversal.java
@@ -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