Skip to content

Commit 38a360b

Browse files
committed
Add solution #144
1 parent 72763cf commit 38a360b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
121|[Best Time to Buy and Sell Stock](./0121-best-time-to-buy-and-sell-stock.js)|Easy|
4646
136|[Single Number](./0136-single-number.js)|Easy|
4747
141|[Linked List Cycle](./0141-linked-list-cycle.js)|Easy|
48+
144|[Binary Tree Preorder Traversal](./0144-binary-tree-preorder-traversal.js)|Easy|
4849
151|[Reverse Words in a String](./0151-reverse-words-in-a-string.js)|Medium|
4950
152|[Maximum Product Subarray](./0152-maximum-product-subarray.js)|Medium|
5051
203|[Remove Linked List Elements](./0203-remove-linked-list-elements.js)|Easy|

Diff for: solutions/0144-binary-tree-preorder-traversal.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 144. Binary Tree Preorder Traversal
3+
* https://leetcode.com/problems/binary-tree-preorder-traversal/
4+
* Difficulty: Easy
5+
*
6+
* Given the root of a binary tree, return the preorder traversal of its nodes' values.
7+
*/
8+
9+
/**
10+
* Definition for a binary tree node.
11+
* function TreeNode(val, left, right) {
12+
* this.val = (val===undefined ? 0 : val)
13+
* this.left = (left===undefined ? null : left)
14+
* this.right = (right===undefined ? null : right)
15+
* }
16+
*/
17+
/**
18+
* @param {TreeNode} root
19+
* @return {number[]}
20+
*/
21+
var preorderTraversal = function(root) {
22+
return root
23+
? [root.val, ...preorderTraversal(root.left), ...preorderTraversal(root.right)]
24+
: [];
25+
};

0 commit comments

Comments
 (0)