File tree 2 files changed +43
-1
lines changed
2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,230 LeetCode solutions in JavaScript
1
+ # 1,231 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1004
1004
1320|[ Minimum Distance to Type a Word Using Two Fingers] ( ./solutions/1320-minimum-distance-to-type-a-word-using-two-fingers.js ) |Hard|
1005
1005
1323|[ Maximum 69 Number] ( ./solutions/1323-maximum-69-number.js ) |Easy|
1006
1006
1324|[ Print Words Vertically] ( ./solutions/1324-print-words-vertically.js ) |Medium|
1007
+ 1325|[ Delete Leaves With a Given Value] ( ./solutions/1325-delete-leaves-with-a-given-value.js ) |Medium|
1007
1008
1331|[ Rank Transform of an Array] ( ./solutions/1331-rank-transform-of-an-array.js ) |Easy|
1008
1009
1332|[ Remove Palindromic Subsequences] ( ./solutions/1332-remove-palindromic-subsequences.js ) |Easy|
1009
1010
1333|[ Filter Restaurants by Vegan-Friendly, Price and Distance] ( ./solutions/1333-filter-restaurants-by-vegan-friendly-price-and-distance.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1325. Delete Leaves With a Given Value
3
+ * https://leetcode.com/problems/delete-leaves-with-a-given-value/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a binary tree root and an integer target, delete all the leaf nodes with value target.
7
+ *
8
+ * Note that once you delete a leaf node with value target, if its parent node becomes a leaf
9
+ * node and has the value target, it should also be deleted (you need to continue doing that
10
+ * until you cannot).
11
+ */
12
+
13
+ /**
14
+ * Definition for a binary tree node.
15
+ * function TreeNode(val, left, right) {
16
+ * this.val = (val===undefined ? 0 : val)
17
+ * this.left = (left===undefined ? null : left)
18
+ * this.right = (right===undefined ? null : right)
19
+ * }
20
+ */
21
+ /**
22
+ * @param {TreeNode } root
23
+ * @param {number } target
24
+ * @return {TreeNode }
25
+ */
26
+ var removeLeafNodes = function ( root , target ) {
27
+ return pruneLeaves ( root ) ;
28
+
29
+ function pruneLeaves ( node ) {
30
+ if ( ! node ) return null ;
31
+
32
+ node . left = pruneLeaves ( node . left ) ;
33
+ node . right = pruneLeaves ( node . right ) ;
34
+
35
+ if ( ! node . left && ! node . right && node . val === target ) {
36
+ return null ;
37
+ }
38
+
39
+ return node ;
40
+ }
41
+ } ;
You can’t perform that action at this time.
0 commit comments