File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 47
47
136|[ Single Number] ( ./0136-single-number.js ) |Easy|
48
48
141|[ Linked List Cycle] ( ./0141-linked-list-cycle.js ) |Easy|
49
49
144|[ Binary Tree Preorder Traversal] ( ./0144-binary-tree-preorder-traversal.js ) |Easy|
50
+ 145|[ Binary Tree Postorder Traversal] ( ./0145-binary-tree-postorder-traversal.js ) |Easy|
50
51
151|[ Reverse Words in a String] ( ./0151-reverse-words-in-a-string.js ) |Medium|
51
52
152|[ Maximum Product Subarray] ( ./0152-maximum-product-subarray.js ) |Medium|
52
53
203|[ Remove Linked List Elements] ( ./0203-remove-linked-list-elements.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 145. Binary Tree Postorder Traversal
3
+ * https://leetcode.com/problems/binary-tree-postorder-traversal/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given the root of a binary tree, return the postorder traversal
7
+ * of its nodes' values.
8
+ */
9
+
10
+ /**
11
+ * Definition for a binary tree node.
12
+ * function TreeNode(val, left, right) {
13
+ * this.val = (val===undefined ? 0 : val)
14
+ * this.left = (left===undefined ? null : left)
15
+ * this.right = (right===undefined ? null : right)
16
+ * }
17
+ */
18
+ /**
19
+ * @param {TreeNode } root
20
+ * @return {number[] }
21
+ */
22
+ var postorderTraversal = function ( root ) {
23
+ if ( ! root ) {
24
+ return [ ] ;
25
+ }
26
+
27
+ return [
28
+ ...postorderTraversal ( root . left ) ,
29
+ ...postorderTraversal ( root . right ) ,
30
+ root . val
31
+ ] ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments