Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 4185ccb

Browse files
committed
1110 added
1 parent aff779f commit 4185ccb

File tree

5 files changed

+108
-27
lines changed

5 files changed

+108
-27
lines changed
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [1110. Delete Nodes And Return Forest](https://leetcode.com/problems/delete-nodes-and-return-forest/)
2+
3+
Given the root of a binary tree, each node in the tree has a distinct value.
4+
5+
After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).
6+
7+
Return the roots of the trees in the remaining forest. You may return the result in any order.
8+
9+
Example 1:
10+
11+
![1](1.png)
12+
13+
```text
14+
Input: root = [1,2,3,4,5,6,7], to_delete = [3,5]
15+
Output: [[1,2,null,4],[6],[7]]
16+
```
17+
18+
Constraints:
19+
20+
- The number of nodes in the given tree is at most 1000.
21+
- Each node has a distinct value between 1 and 1000.
22+
- to_delete.length <= 1000
23+
- to_delete contains distinct values between 1 and 1000.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package problem1110
2+
3+
import "github.com/aQuaYi/LeetCode-in-Go/kit"
4+
5+
// TreeNode is pre-defined
6+
type TreeNode = kit.TreeNode
7+
8+
func delNodes(root *TreeNode, delete []int) []*TreeNode {
9+
10+
return nil
11+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package problem1110
2+
3+
import (
4+
"testing"
5+
6+
"github.com/aQuaYi/LeetCode-in-Go/kit"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
root []int
13+
delete []int
14+
ans [][]int
15+
}{
16+
17+
{
18+
[]int{1, 2, 3, 4, 5, 6, 7},
19+
[]int{3, 5},
20+
[][]int{{1, 2, kit.NULL, 4}, {6}, {7}},
21+
},
22+
23+
// 可以有多个 testcase
24+
}
25+
26+
func Test_delNodes(t *testing.T) {
27+
ast := assert.New(t)
28+
29+
for _, tc := range tcs {
30+
root := kit.Ints2TreeNode(tc.root)
31+
tmps := delNodes(root, tc.delete)
32+
ans := make([][]int, len(tmps))
33+
for i, t := range tmps {
34+
ans[i] = kit.Tree2ints(t)
35+
}
36+
ast.Equal(tc.ans, ans, "输入:%v", tc)
37+
}
38+
}
39+
40+
func Benchmark_delNodes(b *testing.B) {
41+
for i := 0; i < b.N; i++ {
42+
for _, tc := range tcs {
43+
root := kit.Ints2TreeNode(tc.root)
44+
delNodes(root, tc.delete)
45+
}
46+
}
47+
}

leetcode.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
3-
"Ranking": 557,
4-
"Updated": "2019-07-28T19:35:05.371672734+08:00",
3+
"Ranking": 555,
4+
"Updated": "2019-07-29T19:54:58.582329515+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 253,
@@ -1045,7 +1045,7 @@
10451045
"ID": 85,
10461046
"Title": "Maximal Rectangle",
10471047
"TitleSlug": "maximal-rectangle",
1048-
"PassRate": "33%",
1048+
"PassRate": "34%",
10491049
"Difficulty": "Hard",
10501050
"IsAccepted": true,
10511051
"IsPaid": false,
@@ -1177,7 +1177,7 @@
11771177
"ID": 96,
11781178
"Title": "Unique Binary Search Trees",
11791179
"TitleSlug": "unique-binary-search-trees",
1180-
"PassRate": "46%",
1180+
"PassRate": "47%",
11811181
"Difficulty": "Medium",
11821182
"IsAccepted": true,
11831183
"IsPaid": false,
@@ -1681,7 +1681,7 @@
16811681
"ID": 138,
16821682
"Title": "Copy List with Random Pointer",
16831683
"TitleSlug": "copy-list-with-random-pointer",
1684-
"PassRate": "27%",
1684+
"PassRate": "28%",
16851685
"Difficulty": "Medium",
16861686
"IsAccepted": false,
16871687
"IsPaid": false,
@@ -6901,7 +6901,7 @@
69016901
"ID": 573,
69026902
"Title": "Squirrel Simulation",
69036903
"TitleSlug": "squirrel-simulation",
6904-
"PassRate": "54%",
6904+
"PassRate": "53%",
69056905
"Difficulty": "Medium",
69066906
"IsAccepted": false,
69076907
"IsPaid": true,
@@ -7933,7 +7933,7 @@
79337933
"ID": 659,
79347934
"Title": "Split Array into Consecutive Subsequences",
79357935
"TitleSlug": "split-array-into-consecutive-subsequences",
7936-
"PassRate": "40%",
7936+
"PassRate": "41%",
79377937
"Difficulty": "Medium",
79387938
"IsAccepted": true,
79397939
"IsPaid": false,
@@ -8161,7 +8161,7 @@
81618161
"ID": 678,
81628162
"Title": "Valid Parenthesis String",
81638163
"TitleSlug": "valid-parenthesis-string",
8164-
"PassRate": "33%",
8164+
"PassRate": "32%",
81658165
"Difficulty": "Medium",
81668166
"IsAccepted": true,
81678167
"IsPaid": false,
@@ -8365,7 +8365,7 @@
83658365
"ID": 695,
83668366
"Title": "Max Area of Island",
83678367
"TitleSlug": "max-area-of-island",
8368-
"PassRate": "57%",
8368+
"PassRate": "58%",
83698369
"Difficulty": "Medium",
83708370
"IsAccepted": true,
83718371
"IsPaid": false,
@@ -8401,7 +8401,7 @@
84018401
"ID": 698,
84028402
"Title": "Partition to K Equal Sum Subsets",
84038403
"TitleSlug": "partition-to-k-equal-sum-subsets",
8404-
"PassRate": "42%",
8404+
"PassRate": "43%",
84058405
"Difficulty": "Medium",
84068406
"IsAccepted": true,
84078407
"IsPaid": false,
@@ -9337,7 +9337,7 @@
93379337
"ID": 776,
93389338
"Title": "Split BST",
93399339
"TitleSlug": "split-bst",
9340-
"PassRate": "53%",
9340+
"PassRate": "52%",
93419341
"Difficulty": "Medium",
93429342
"IsAccepted": false,
93439343
"IsPaid": true,
@@ -10033,7 +10033,7 @@
1003310033
"ID": 834,
1003410034
"Title": "Sum of Distances in Tree",
1003510035
"TitleSlug": "sum-of-distances-in-tree",
10036-
"PassRate": "39%",
10036+
"PassRate": "40%",
1003710037
"Difficulty": "Hard",
1003810038
"IsAccepted": true,
1003910039
"IsPaid": false,
@@ -11869,7 +11869,7 @@
1186911869
"ID": 987,
1187011870
"Title": "Vertical Order Traversal of a Binary Tree",
1187111871
"TitleSlug": "vertical-order-traversal-of-a-binary-tree",
11872-
"PassRate": "32%",
11872+
"PassRate": "31%",
1187311873
"Difficulty": "Medium",
1187411874
"IsAccepted": true,
1187511875
"IsPaid": false,
@@ -12205,7 +12205,7 @@
1220512205
"ID": 1015,
1220612206
"Title": "Smallest Integer Divisible by K",
1220712207
"TitleSlug": "smallest-integer-divisible-by-k",
12208-
"PassRate": "28%",
12208+
"PassRate": "29%",
1220912209
"Difficulty": "Medium",
1221012210
"IsAccepted": true,
1221112211
"IsPaid": false,
@@ -12613,7 +12613,7 @@
1261312613
"ID": 1049,
1261412614
"Title": "Last Stone Weight II",
1261512615
"TitleSlug": "last-stone-weight-ii",
12616-
"PassRate": "40%",
12616+
"PassRate": "39%",
1261712617
"Difficulty": "Medium",
1261812618
"IsAccepted": true,
1261912619
"IsPaid": false,
@@ -12757,7 +12757,7 @@
1275712757
"ID": 1061,
1275812758
"Title": "Lexicographically Smallest Equivalent String",
1275912759
"TitleSlug": "lexicographically-smallest-equivalent-string",
12760-
"PassRate": "61%",
12760+
"PassRate": "62%",
1276112761
"Difficulty": "Medium",
1276212762
"IsAccepted": false,
1276312763
"IsPaid": true,
@@ -12781,7 +12781,7 @@
1278112781
"ID": 1063,
1278212782
"Title": "Number of Valid Subarrays",
1278312783
"TitleSlug": "number-of-valid-subarrays",
12784-
"PassRate": "72%",
12784+
"PassRate": "73%",
1278512785
"Difficulty": "Hard",
1278612786
"IsAccepted": false,
1278712787
"IsPaid": true,
@@ -13093,7 +13093,7 @@
1309313093
"ID": 1089,
1309413094
"Title": "Duplicate Zeros",
1309513095
"TitleSlug": "duplicate-zeros",
13096-
"PassRate": "58%",
13096+
"PassRate": "59%",
1309713097
"Difficulty": "Easy",
1309813098
"IsAccepted": true,
1309913099
"IsPaid": false,
@@ -13465,7 +13465,7 @@
1346513465
"ID": 1120,
1346613466
"Title": "Maximum Average Subtree",
1346713467
"TitleSlug": "maximum-average-subtree",
13468-
"PassRate": "61%",
13468+
"PassRate": "60%",
1346913469
"Difficulty": "Medium",
1347013470
"IsAccepted": false,
1347113471
"IsPaid": true,
@@ -13597,7 +13597,7 @@
1359713597
"ID": 1131,
1359813598
"Title": "Maximum of Absolute Value Expression",
1359913599
"TitleSlug": "maximum-of-absolute-value-expression",
13600-
"PassRate": "49%",
13600+
"PassRate": "50%",
1360113601
"Difficulty": "Medium",
1360213602
"IsAccepted": false,
1360313603
"IsPaid": false,
@@ -13633,7 +13633,7 @@
1363313633
"ID": 1134,
1363413634
"Title": "Armstrong Number",
1363513635
"TitleSlug": "armstrong-number",
13636-
"PassRate": "82%",
13636+
"PassRate": "81%",
1363713637
"Difficulty": "Easy",
1363813638
"IsAccepted": false,
1363913639
"IsPaid": true,
@@ -13645,7 +13645,7 @@
1364513645
"ID": 1135,
1364613646
"Title": "Connecting Cities With Minimum Cost",
1364713647
"TitleSlug": "connecting-cities-with-minimum-cost",
13648-
"PassRate": "40%",
13648+
"PassRate": "42%",
1364913649
"Difficulty": "Medium",
1365013650
"IsAccepted": false,
1365113651
"IsPaid": true,
@@ -13657,7 +13657,7 @@
1365713657
"ID": 1136,
1365813658
"Title": "Parallel Courses",
1365913659
"TitleSlug": "parallel-courses",
13660-
"PassRate": "55%",
13660+
"PassRate": "56%",
1366113661
"Difficulty": "Hard",
1366213662
"IsAccepted": false,
1366313663
"IsPaid": true,
@@ -13669,7 +13669,7 @@
1366913669
"ID": 1137,
1367013670
"Title": "N-th Tribonacci Number",
1367113671
"TitleSlug": "n-th-tribonacci-number",
13672-
"PassRate": "64%",
13672+
"PassRate": "63%",
1367313673
"Difficulty": "Easy",
1367413674
"IsAccepted": false,
1367513675
"IsPaid": false,
@@ -13681,7 +13681,7 @@
1368113681
"ID": 1138,
1368213682
"Title": "Alphabet Board Path",
1368313683
"TitleSlug": "alphabet-board-path",
13684-
"PassRate": "39%",
13684+
"PassRate": "41%",
1368513685
"Difficulty": "Medium",
1368613686
"IsAccepted": false,
1368713687
"IsPaid": false,
@@ -13693,7 +13693,7 @@
1369313693
"ID": 1139,
1369413694
"Title": "Largest 1-Bordered Square",
1369513695
"TitleSlug": "largest-1-bordered-square",
13696-
"PassRate": "37%",
13696+
"PassRate": "39%",
1369713697
"Difficulty": "Medium",
1369813698
"IsAccepted": false,
1369913699
"IsPaid": false,
@@ -13705,7 +13705,7 @@
1370513705
"ID": 1140,
1370613706
"Title": "Stone Game II",
1370713707
"TitleSlug": "stone-game-ii",
13708-
"PassRate": "56%",
13708+
"PassRate": "58%",
1370913709
"Difficulty": "Medium",
1371013710
"IsAccepted": false,
1371113711
"IsPaid": false,

0 commit comments

Comments
 (0)