Skip to content

Commit c70a3d5

Browse files
committed
Leetcode 145 Binary Tree Postorder Traversal
1 parent 80e1106 commit c70a3d5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public List<Integer> postorderTraversal(TreeNode root) {
3+
LinkedList<Integer> ans = new LinkedList<>();
4+
if(root == null) return ans;
5+
Deque<TreeNode> stack = new ArrayDeque<>();
6+
stack.push(root);
7+
while(!stack.isEmpty()) {
8+
TreeNode node = stack.pop();
9+
ans.addFirst(node.val);
10+
if(node.left !=null) stack.push(node.left);
11+
if(node.right != null) stack.push(node.right);
12+
}
13+
return ans;
14+
}
15+
}

0 commit comments

Comments
 (0)