We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab5feea commit 5787f2dCopy full SHA for 5787f2d
src/Algorithms/0145.binary-tree-postorder-traversal/binary-tree-postorder-traversal.php
@@ -0,0 +1,30 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * class TreeNode {
4
+ * public $val = null;
5
+ * public $left = null;
6
+ * public $right = null;
7
+ * function __construct($value) { $this->val = $value; }
8
+ * }
9
+ */
10
+class Solution {
11
+
12
+ /**
13
+ * @param TreeNode $root
14
+ * @return Integer[]
15
16
+ function postorderTraversal($root) {
17
+ $postOrder = [];
18
+ $stack = [];
19
+ $node = $root;
20
+ while (!empty($stack) || $node != null) {
21
+ while ($node != null) {
22
+ array_push($stack, $node);
23
+ array_unshift($postOrder, $node->val);
24
+ $node = $node->right;
25
+ }
26
+ $node = array_pop($stack)->left;
27
28
+ return $postOrder;
29
30
+}
0 commit comments