-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathLint68.java
More file actions
30 lines (30 loc) · 806 Bytes
/
Lint68.java
File metadata and controls
30 lines (30 loc) · 806 Bytes
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
/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/
public class Solution {
/**
* @param root: The root of binary tree.
* @return: Postorder in ArrayList which contains node values.
*/
public ArrayList<Integer> postorderTraversal(TreeNode root) {
// write your code here
ArrayList<Integer> list = new ArrayList<>();
helper(list,root);
return list;
}
public void helper(ArrayList<Integer> list,TreeNode node){
if(node != null){
helper(list,node.left);
helper(list,node.right);
list.add(node.val);
}
}
}