Skip to content

Commit 06e64c6

Browse files
committed
Add solution #145
1 parent b9145fc commit 06e64c6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
136|[Single Number](./0136-single-number.js)|Easy|
4848
141|[Linked List Cycle](./0141-linked-list-cycle.js)|Easy|
4949
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|
5051
151|[Reverse Words in a String](./0151-reverse-words-in-a-string.js)|Medium|
5152
152|[Maximum Product Subarray](./0152-maximum-product-subarray.js)|Medium|
5253
203|[Remove Linked List Elements](./0203-remove-linked-list-elements.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};

0 commit comments

Comments
 (0)