Skip to content

Commit 44bf7ab

Browse files
authored
feat: add biweekly contest 138 and weekly contest 413 (#3465)
1 parent 30ca343 commit 44bf7ab

File tree

111 files changed

+4387
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+4387
-293
lines changed

lcof2/剑指 Offer II 077. 链表排序/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -395,29 +395,29 @@ class Solution {
395395
guard let head = head, head.next != nil else {
396396
return head
397397
}
398-
398+
399399
var slow: ListNode? = head
400400
var fast: ListNode? = head.next
401-
401+
402402
while fast != nil && fast?.next != nil {
403403
slow = slow?.next
404404
fast = fast?.next?.next
405405
}
406-
406+
407407
let mid = slow?.next
408408
slow?.next = nil
409-
409+
410410
let left = sortList(head)
411411
let right = sortList(mid)
412-
412+
413413
return merge(left, right)
414414
}
415-
415+
416416
private func merge(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {
417417
let dummy = ListNode()
418418
var cur = dummy
419419
var l1 = l1, l2 = l2
420-
420+
421421
while let node1 = l1, let node2 = l2 {
422422
if node1.val <= node2.val {
423423
cur.next = node1
@@ -428,7 +428,7 @@ class Solution {
428428
}
429429
cur = cur.next!
430430
}
431-
431+
432432
cur.next = l1 ?? l2
433433
return dummy.next
434434
}

lcof2/剑指 Offer II 078. 合并排序链表/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,20 +381,20 @@ class Solution {
381381
if n == 0 {
382382
return nil
383383
}
384-
384+
385385
var mergedList: ListNode? = lists[0]
386386
for i in 1..<n {
387387
mergedList = mergeLists(mergedList, lists[i])
388388
}
389389
return mergedList
390390
}
391-
391+
392392
private func mergeLists(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {
393393
let dummy = ListNode()
394394
var cur = dummy
395395
var l1 = l1
396396
var l2 = l2
397-
397+
398398
while let node1 = l1, let node2 = l2 {
399399
if node1.val <= node2.val {
400400
cur.next = node1

lcof2/剑指 Offer II 079. 所有子集/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class Solution {
197197
dfs(0, nums, [], &res)
198198
return res
199199
}
200-
200+
201201
private func dfs(_ i: Int, _ nums: [Int], _ current: [Int], _ res: inout [[Int]]) {
202202
res.append(current)
203203
for j in i..<nums.count {

lcof2/剑指 Offer II 080. 含有 k 个元素的组合/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ class Solution {
160160
dfs(1, n, k, [], &res)
161161
return res
162162
}
163-
163+
164164
private func dfs(_ start: Int, _ n: Int, _ k: Int, _ current: [Int], _ res: inout [[Int]]) {
165165
if current.count == k {
166166
res.append(current)
167167
return
168168
}
169-
169+
170170
if start > n {
171171
return
172172
}
173-
173+
174174
for i in start...n {
175175
var newCurrent = current
176176
newCurrent.append(i)

solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md

+32-13
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,44 @@ tags:
2323

2424
<p>&nbsp;</p>
2525
<p><strong class="example">Example 1:</strong></p>
26-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/images/inorder_1.jpg" style="width: 125px; height: 200px;" />
27-
<pre>
28-
<strong>Input:</strong> root = [1,null,2,3]
29-
<strong>Output:</strong> [1,3,2]
30-
</pre>
26+
27+
<div class="example-block">
28+
<p><strong>Input:</strong> <span class="example-io">root = [1,null,2,3]</span></p>
29+
30+
<p><strong>Output:</strong> <span class="example-io">[1,3,2]</span></p>
31+
32+
<p><strong>Explanation:</strong></p>
33+
34+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/images/screenshot-2024-08-29-202743.png" style="width: 200px; height: 264px;" /></p>
35+
</div>
3136

3237
<p><strong class="example">Example 2:</strong></p>
3338

34-
<pre>
35-
<strong>Input:</strong> root = []
36-
<strong>Output:</strong> []
37-
</pre>
39+
<div class="example-block">
40+
<p><strong>Input:</strong> <span class="example-io">root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>
41+
42+
<p><strong>Output:</strong> <span class="example-io">[4,2,6,5,7,1,3,9,8]</span></p>
43+
44+
<p><strong>Explanation:</strong></p>
45+
46+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/images/tree_2.png" style="width: 350px; height: 286px;" /></p>
47+
</div>
3848

3949
<p><strong class="example">Example 3:</strong></p>
4050

41-
<pre>
42-
<strong>Input:</strong> root = [1]
43-
<strong>Output:</strong> [1]
44-
</pre>
51+
<div class="example-block">
52+
<p><strong>Input:</strong> <span class="example-io">root = []</span></p>
53+
54+
<p><strong>Output:</strong> <span class="example-io">[]</span></p>
55+
</div>
56+
57+
<p><strong class="example">Example 4:</strong></p>
58+
59+
<div class="example-block">
60+
<p><strong>Input:</strong> <span class="example-io">root = [1]</span></p>
61+
62+
<p><strong>Output:</strong> <span class="example-io">[1]</span></p>
63+
</div>
4564

4665
<p>&nbsp;</p>
4766
<p><strong>Constraints:</strong></p>
Loading
Loading

solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md

+38-33
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,60 @@ tags:
1919

2020
<!-- description:start -->
2121

22-
<p>给你二叉树的根节点 <code>root</code> ,返回它节点值的 <strong>前序</strong><em> </em>遍历。</p>
22+
<p>给你二叉树的根节点 <code>root</code> ,返回它节点值的&nbsp;<strong>前序</strong><em>&nbsp;</em>遍历。</p>
2323

24-
<p> </p>
24+
<p>&nbsp;</p>
2525

26-
<p><strong>示例 1:</strong></p>
27-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/inorder_1.jpg" style="width: 202px; height: 324px;" />
28-
<pre>
29-
<strong>输入:</strong>root = [1,null,2,3]
30-
<strong>输出:</strong>[1,2,3]
31-
</pre>
26+
<p><strong class="example">示例 1:</strong></p>
3227

33-
<p><strong>示例 2:</strong></p>
28+
<div class="example-block">
29+
<p><strong>输入:</strong><span class="example-io">root = [1,null,2,3]</span></p>
3430

35-
<pre>
36-
<strong>输入:</strong>root = []
37-
<strong>输出:</strong>[]
38-
</pre>
31+
<p><strong>输出:</strong><span class="example-io">[1,2,3]</span></p>
3932

40-
<p><strong>示例 3:</strong></p>
33+
<p><strong>解释:</strong></p>
4134

42-
<pre>
43-
<strong>输入:</strong>root = [1]
44-
<strong>输出:</strong>[1]
45-
</pre>
35+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/screenshot-2024-08-29-202743.png" style="width: 200px; height: 264px;" /></p>
36+
</div>
4637

47-
<p><strong>示例 4:</strong></p>
48-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/inorder_5.jpg" style="width: 202px; height: 202px;" />
49-
<pre>
50-
<strong>输入:</strong>root = [1,2]
51-
<strong>输出:</strong>[1,2]
52-
</pre>
38+
<p><strong class="example">示例 2:</strong></p>
5339

54-
<p><strong>示例 5:</strong></p>
55-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/inorder_4.jpg" style="width: 202px; height: 202px;" />
56-
<pre>
57-
<strong>输入:</strong>root = [1,null,2]
58-
<strong>输出:</strong>[1,2]
59-
</pre>
40+
<div class="example-block">
41+
<p><span class="example-io"><b>输入:</b>root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>
6042

61-
<p> </p>
43+
<p><span class="example-io"><b>输出:</b>[1,2,4,5,6,7,3,8,9]</span></p>
44+
45+
<p><strong>解释:</strong></p>
46+
47+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/tree_2.png" style="width: 350px; height: 286px;" /></p>
48+
</div>
49+
50+
<p><strong class="example">示例 3:</strong></p>
51+
52+
<div class="example-block">
53+
<p><span class="example-io"><b>输入:</b>root = []</span></p>
54+
55+
<p><span class="example-io"><b>输出:</b>[]</span></p>
56+
</div>
57+
58+
<p><strong class="example">示例 4:</strong></p>
59+
60+
<div class="example-block">
61+
<p><strong>输入:</strong><span class="example-io">root = [1]</span></p>
62+
63+
<p><span class="example-io"><b>输出:</b>[1]</span></p>
64+
</div>
65+
66+
<p>&nbsp;</p>
6267

6368
<p><strong>提示:</strong></p>
6469

6570
<ul>
6671
<li>树中节点数目在范围 <code>[0, 100]</code> 内</li>
67-
<li><code>-100 <= Node.val <= 100</code></li>
72+
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
6873
</ul>
6974

70-
<p> </p>
75+
<p>&nbsp;</p>
7176

7277
<p><strong>进阶:</strong>递归算法很简单,你可以通过迭代算法完成吗?</p>
7378

solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md

+32-13
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,44 @@ tags:
2323

2424
<p>&nbsp;</p>
2525
<p><strong class="example">Example 1:</strong></p>
26-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/inorder_1.jpg" style="width: 125px; height: 200px;" />
27-
<pre>
28-
<strong>Input:</strong> root = [1,null,2,3]
29-
<strong>Output:</strong> [1,2,3]
30-
</pre>
26+
27+
<div class="example-block">
28+
<p><strong>Input:</strong> <span class="example-io">root = [1,null,2,3]</span></p>
29+
30+
<p><strong>Output:</strong> <span class="example-io">[1,2,3]</span></p>
31+
32+
<p><strong>Explanation:</strong></p>
33+
34+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/screenshot-2024-08-29-202743.png" style="width: 200px; height: 264px;" /></p>
35+
</div>
3136

3237
<p><strong class="example">Example 2:</strong></p>
3338

34-
<pre>
35-
<strong>Input:</strong> root = []
36-
<strong>Output:</strong> []
37-
</pre>
39+
<div class="example-block">
40+
<p><strong>Input:</strong> <span class="example-io">root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>
41+
42+
<p><strong>Output:</strong> <span class="example-io">[1,2,4,5,6,7,3,8,9]</span></p>
43+
44+
<p><strong>Explanation:</strong></p>
45+
46+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/images/tree_2.png" style="width: 350px; height: 286px;" /></p>
47+
</div>
3848

3949
<p><strong class="example">Example 3:</strong></p>
4050

41-
<pre>
42-
<strong>Input:</strong> root = [1]
43-
<strong>Output:</strong> [1]
44-
</pre>
51+
<div class="example-block">
52+
<p><strong>Input:</strong> <span class="example-io">root = []</span></p>
53+
54+
<p><strong>Output:</strong> <span class="example-io">[]</span></p>
55+
</div>
56+
57+
<p><strong class="example">Example 4:</strong></p>
58+
59+
<div class="example-block">
60+
<p><strong>Input:</strong> <span class="example-io">root = [1]</span></p>
61+
62+
<p><strong>Output:</strong> <span class="example-io">[1]</span></p>
63+
</div>
4564

4665
<p>&nbsp;</p>
4766
<p><strong>Constraints:</strong></p>
Loading

solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md

+39-20
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,45 @@ tags:
2323

2424
<p>&nbsp;</p>
2525

26-
<p><strong>示例 1:</strong></p>
27-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/images/pre1.jpg" style="width: 127px; height: 200px;" />
28-
<pre>
29-
<strong>输入:</strong>root = [1,null,2,3]
30-
<strong>输出:</strong>[3,2,1]
31-
</pre>
32-
33-
<p><strong>示例 2:</strong></p>
34-
35-
<pre>
36-
<strong>输入:</strong>root = []
37-
<strong>输出:</strong>[]
38-
</pre>
39-
40-
<p><strong>示例 3:</strong></p>
41-
42-
<pre>
43-
<strong>输入:</strong>root = [1]
44-
<strong>输出:</strong>[1]
45-
</pre>
26+
<p><strong class="example">示例 1:</strong></p>
27+
28+
<div class="example-block">
29+
<p><span class="example-io"><b>输入:</b>root = [1,null,2,3]</span></p>
30+
31+
<p><span class="example-io"><b>输出:</b>[3,2,1]</span></p>
32+
33+
<p><strong>解释:</strong></p>
34+
35+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/images/screenshot-2024-08-29-202743.png" style="width: 200px; height: 264px;" /></p>
36+
</div>
37+
38+
<p><strong class="example">示例 2:</strong></p>
39+
40+
<div class="example-block">
41+
<p><span class="example-io"><b>输入:</b>root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>
42+
43+
<p><span class="example-io"><b>输出:</b>[4,6,7,5,2,9,8,3,1]</span></p>
44+
45+
<p><strong>解释:</strong></p>
46+
47+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/images/tree_2.png" style="width: 350px; height: 286px;" /></p>
48+
</div>
49+
50+
<p><strong class="example">示例 3:</strong></p>
51+
52+
<div class="example-block">
53+
<p><span class="example-io"><b>输入:</b>root = []</span></p>
54+
55+
<p><span class="example-io"><b>输出:</b>[]</span></p>
56+
</div>
57+
58+
<p><strong class="example">示例 4:</strong></p>
59+
60+
<div class="example-block">
61+
<p><span class="example-io"><b>输入:</b>root = [1]</span></p>
62+
63+
<p><span class="example-io"><b>输出:</b>[1]</span></p>
64+
</div>
4665

4766
<p>&nbsp;</p>
4867

0 commit comments

Comments
 (0)