/PostorderRecursive.java Secret
Created
June 10, 2017 18:02
Star
You must be signed in to star a gist
Postorder recursive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.interviewbytes.trees; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class PostorderRecursive { | |
public List<Integer> postorderTraversal(TreeNode root) { | |
List<Integer> list = new ArrayList<>(); | |
helper(root, list); | |
return list; | |
} | |
private void helper(TreeNode node, List<Integer> list) { | |
if (node == null) return; | |
helper(node.left, list); | |
helper(node.right, list); | |
list.add(node.val); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.interviewbytes.trees; | |
public class TreeNode { | |
int val; | |
TreeNode left; | |
TreeNode right; | |
TreeNode(int x) { | |
val = x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment