-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP113.java
38 lines (32 loc) · 808 Bytes
/
P113.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;
import java.io.*;
/*
Following is the Binary Tree node structure:
public class TreeNode {
int data;
TreeNode left;
TreeNode right;
TreeNode() {}
TreeNode(int val) { this.data = val; }
TreeNode(int val, TreeNode left, TreeNode right) {
this.data = val;
this.left = left;
this.right = right;
}
}
*/
public class P113 {
static List<Integer> res;
static void post(TreeNode root) {
if (root == null)
return;
post(root.left);
post(root.right);
res.add(root.data);
}
public static List<Integer> getPostOrderTraversal(TreeNode root) {
res = new ArrayList<Integer>();
post(root);
return res;
}
}