Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add biweekly contest 138 and weekly contest 413 #3465

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lcof2/剑指 Offer II 077. 链表排序/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,29 +395,29 @@ class Solution {
guard let head = head, head.next != nil else {
return head
}

var slow: ListNode? = head
var fast: ListNode? = head.next

while fast != nil && fast?.next != nil {
slow = slow?.next
fast = fast?.next?.next
}

let mid = slow?.next
slow?.next = nil

let left = sortList(head)
let right = sortList(mid)

return merge(left, right)
}

private func merge(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {
let dummy = ListNode()
var cur = dummy
var l1 = l1, l2 = l2

while let node1 = l1, let node2 = l2 {
if node1.val <= node2.val {
cur.next = node1
Expand All @@ -428,7 +428,7 @@ class Solution {
}
cur = cur.next!
}

cur.next = l1 ?? l2
return dummy.next
}
Expand Down
6 changes: 3 additions & 3 deletions lcof2/剑指 Offer II 078. 合并排序链表/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,20 @@ class Solution {
if n == 0 {
return nil
}

var mergedList: ListNode? = lists[0]
for i in 1..<n {
mergedList = mergeLists(mergedList, lists[i])
}
return mergedList
}

private func mergeLists(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {
let dummy = ListNode()
var cur = dummy
var l1 = l1
var l2 = l2

while let node1 = l1, let node2 = l2 {
if node1.val <= node2.val {
cur.next = node1
Expand Down
2 changes: 1 addition & 1 deletion lcof2/剑指 Offer II 079. 所有子集/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Solution {
dfs(0, nums, [], &res)
return res
}

private func dfs(_ i: Int, _ nums: [Int], _ current: [Int], _ res: inout [[Int]]) {
res.append(current)
for j in i..<nums.count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ class Solution {
dfs(1, n, k, [], &res)
return res
}

private func dfs(_ start: Int, _ n: Int, _ k: Int, _ current: [Int], _ res: inout [[Int]]) {
if current.count == k {
res.append(current)
return
}

if start > n {
return
}

for i in start...n {
var newCurrent = current
newCurrent.append(i)
Expand Down
45 changes: 32 additions & 13 deletions solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,44 @@ tags:

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<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;" />
<pre>
<strong>Input:</strong> root = [1,null,2,3]
<strong>Output:</strong> [1,3,2]
</pre>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = [1,null,2,3]</span></p>

<p><strong>Output:</strong> <span class="example-io">[1,3,2]</span></p>

<p><strong>Explanation:</strong></p>

<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>
</div>

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

<pre>
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>

<p><strong>Output:</strong> <span class="example-io">[4,2,6,5,7,1,3,9,8]</span></p>

<p><strong>Explanation:</strong></p>

<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>
</div>

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

<pre>
<strong>Input:</strong> root = [1]
<strong>Output:</strong> [1]
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = []</span></p>

<p><strong>Output:</strong> <span class="example-io">[]</span></p>
</div>

<p><strong class="example">Example 4:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = [1]</span></p>

<p><strong>Output:</strong> <span class="example-io">[1]</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 38 additions & 33 deletions solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,60 @@ tags:

<!-- description:start -->

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

<p> </p>
<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<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;" />
<pre>
<strong>输入:</strong>root = [1,null,2,3]
<strong>输出:</strong>[1,2,3]
</pre>
<p><strong class="example">示例 1:</strong></p>

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

<pre>
<strong>输入:</strong>root = []
<strong>输出:</strong>[]
</pre>
<p><strong>输出:</strong><span class="example-io">[1,2,3]</span></p>

<p><strong>示例 3:</strong></p>
<p><strong>解释:</strong></p>

<pre>
<strong>输入:</strong>root = [1]
<strong>输出:</strong>[1]
</pre>
<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>
</div>

<p><strong>示例 4:</strong></p>
<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;" />
<pre>
<strong>输入:</strong>root = [1,2]
<strong>输出:</strong>[1,2]
</pre>
<p><strong class="example">示例 2:</strong></p>

<p><strong>示例 5:</strong></p>
<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;" />
<pre>
<strong>输入:</strong>root = [1,null,2]
<strong>输出:</strong>[1,2]
</pre>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>

<p> </p>
<p><span class="example-io"><b>输出:</b>[1,2,4,5,6,7,3,8,9]</span></p>

<p><strong>解释:</strong></p>

<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>
</div>

<p><strong class="example">示例 3:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>root = []</span></p>

<p><span class="example-io"><b>输出:</b>[]</span></p>
</div>

<p><strong class="example">示例 4:</strong></p>

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">root = [1]</span></p>

<p><span class="example-io"><b>输出:</b>[1]</span></p>
</div>

<p>&nbsp;</p>

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

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

<p> </p>
<p>&nbsp;</p>

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

Expand Down
45 changes: 32 additions & 13 deletions solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,44 @@ tags:

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<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;" />
<pre>
<strong>Input:</strong> root = [1,null,2,3]
<strong>Output:</strong> [1,2,3]
</pre>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = [1,null,2,3]</span></p>

<p><strong>Output:</strong> <span class="example-io">[1,2,3]</span></p>

<p><strong>Explanation:</strong></p>

<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>
</div>

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

<pre>
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>

<p><strong>Output:</strong> <span class="example-io">[1,2,4,5,6,7,3,8,9]</span></p>

<p><strong>Explanation:</strong></p>

<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>
</div>

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

<pre>
<strong>Input:</strong> root = [1]
<strong>Output:</strong> [1]
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = []</span></p>

<p><strong>Output:</strong> <span class="example-io">[]</span></p>
</div>

<p><strong class="example">Example 4:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">root = [1]</span></p>

<p><strong>Output:</strong> <span class="example-io">[1]</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 39 additions & 20 deletions solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,45 @@ tags:

<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<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;" />
<pre>
<strong>输入:</strong>root = [1,null,2,3]
<strong>输出:</strong>[3,2,1]
</pre>

<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong>root = []
<strong>输出:</strong>[]
</pre>

<p><strong>示例 3:</strong></p>

<pre>
<strong>输入:</strong>root = [1]
<strong>输出:</strong>[1]
</pre>
<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>root = [1,null,2,3]</span></p>

<p><span class="example-io"><b>输出:</b>[3,2,1]</span></p>

<p><strong>解释:</strong></p>

<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>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>root = [1,2,3,4,5,null,8,null,null,6,7,9]</span></p>

<p><span class="example-io"><b>输出:</b>[4,6,7,5,2,9,8,3,1]</span></p>

<p><strong>解释:</strong></p>

<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>
</div>

<p><strong class="example">示例 3:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>root = []</span></p>

<p><span class="example-io"><b>输出:</b>[]</span></p>
</div>

<p><strong class="example">示例 4:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>root = [1]</span></p>

<p><span class="example-io"><b>输出:</b>[1]</span></p>
</div>

<p>&nbsp;</p>

Expand Down
Loading
Loading