There was an error while loading. Please reload this page.
1 parent 80e1106 commit c70a3d5Copy full SHA for c70a3d5
0145_Binary Tree Postorder Traversal/BinaryTreePostorderTraversal_3.java
@@ -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