Skip to content

feat: add solutions to lc problem: No.3344 #3731

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

Merged
merged 1 commit into from
Nov 8, 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
10 changes: 5 additions & 5 deletions lcp/LCP 03. 机器人大冒险/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Solution {
var visited: Set<[Int]> = []
var i = 0, j = 0
visited.insert([i, j])

for c in command {
if c == "U" {
j += 1
Expand All @@ -256,16 +256,16 @@ class Solution {
}
visited.insert([i, j])
}

func canReach(_ targetX: Int, _ targetY: Int) -> Bool {
let k = min(targetX / i, targetY / j)
return visited.contains([targetX - k * i, targetY - k * j])
}

if !canReach(x, y) {
return false
}

for obstacle in obstacles {
let obstacleX = obstacle[0]
let obstacleY = obstacle[1]
Expand All @@ -276,7 +276,7 @@ class Solution {
return false
}
}

return true
}
}
Expand Down
6 changes: 4 additions & 2 deletions solution/0400-0499/0410.Split Array Largest Sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ tags:

<!-- description:start -->

<p>给定一个非负整数数组 <code>nums</code> 和一个整数&nbsp;<code>k</code> ,你需要将这个数组分成&nbsp;<code>k</code><em>&nbsp;</em>个非空的连续子数组。</p>
<p>给定一个非负整数数组 <code>nums</code> 和一个整数&nbsp;<code>k</code> ,你需要将这个数组分成&nbsp;<code>k</code><em>&nbsp;</em>个非空的连续子数组,使得这&nbsp;<code>k</code><em>&nbsp;</em>个子数组各自和的最大值 <strong>最小</strong>。</p>

<p>设计一个算法使得这&nbsp;<code>k</code><em>&nbsp;</em>个子数组各自和的最大值最小。</p>
<p>返回分割后最小的和的最大值。</p>

<p><strong>子数组</strong> 是数组中连续的部份。</p>

<p>&nbsp;</p>

Expand Down
8 changes: 4 additions & 4 deletions solution/0600-0699/0636.Exclusive Time of Functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ tags:
<strong>输入:</strong>n = 2, logs = ["0:start:0","1:start:2","1:end:5","0:end:6"]
<strong>输出:</strong>[3,4]
<strong>解释:</strong>
函数 0 在时间戳 0 的起始开始执行,执行 2 个单位时间,于时间戳 1 的末尾结束执行。
函数 1 在时间戳 2 的起始开始执行,执行 4 个单位时间,于时间戳 5 的末尾结束执行。
函数 0 在时间戳 6 的开始恢复执行,执行 1 个单位时间。
所以函数 0 总共执行 2 + 1 = 3 个单位时间,函数 1 总共执行 4 个单位时间。
函数 0 在时间戳 0 的起始开始执行,执行 2 个单位时间,于时间戳 1 的末尾结束执行。
函数 1 在时间戳 2 的起始开始执行,执行 4 个单位时间,于时间戳 5 的末尾结束执行。
函数 0 在时间戳 6 的开始恢复执行,执行 1 个单位时间。
所以函数 0 总共执行 2 + 1 = 3 个单位时间,函数 1 总共执行 4 个单位时间。
</pre>

<p><strong>示例 2:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tags:
<pre>
<strong>Input:</strong> root = [4,8,5,0,1,null,6]
<strong>Output:</strong> 5
<strong>Explanation:</strong>
<strong>Explanation:</strong>
For the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.
For the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.
For the node with value 0: The average of its subtree is 0 / 1 = 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tags:
<pre>
<strong>Input:</strong> nums = [10,4,-8,7]
<strong>Output:</strong> 2
<strong>Explanation:</strong>
<strong>Explanation:</strong>
There are three ways of splitting nums into two non-empty parts:
- Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 &gt;= 3, i = 0 is a valid split.
- Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 &gt;= -1, i = 1 is a valid split.
Expand All @@ -49,9 +49,9 @@ Thus, the number of valid splits in nums is 2.
<pre>
<strong>Input:</strong> nums = [2,3,1,0]
<strong>Output:</strong> 2
<strong>Explanation:</strong>
<strong>Explanation:</strong>
There are two valid splits in nums:
- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 &gt;= 1, i = 1 is a valid split.
- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 &gt;= 1, i = 1 is a valid split.
- Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 &gt;= 0, i = 2 is a valid split.
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tags:
[null, false, false, true, false]

<strong>解释:</strong>
DataStream dataStream = new DataStream(4, 3); // value = 4, k = 3
DataStream dataStream = new DataStream(4, 3); // value = 4, k = 3
dataStream.consec(4); // 数据流中只有 1 个整数,所以返回 False 。
dataStream.consec(4); // 数据流中只有 2 个整数
// 由于 2 小于 k ,返回 False 。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ tags:
[null, false, false, true, false]

<strong>Explanation</strong>
DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3
dataStream.consec(4); // Only 1 integer is parsed, so returns False.
DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3
dataStream.consec(4); // Only 1 integer is parsed, so returns False.
dataStream.consec(4); // Only 2 integers are parsed.
// Since 2 is less than k, returns False.
dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True.
// Since 2 is less than k, returns False.
dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True.
dataStream.consec(3); // The last k integers parsed in the stream are [4,4,3].
// Since 3 is not equal to value, it returns False.
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ tags:
<pre>
<strong>Input:</strong> stations = [1,2,4,5,0], r = 1, k = 2
<strong>Output:</strong> 5
<strong>Explanation:</strong>
One of the optimal ways is to install both the power stations at city 1.
<strong>Explanation:</strong>
One of the optimal ways is to install both the power stations at city 1.
So stations will become [1,4,4,5,0].
- City 0 is provided by 1 + 4 = 5 power stations.
- City 1 is provided by 1 + 4 + 4 = 9 power stations.
Expand All @@ -62,7 +62,7 @@ Since it is not possible to obtain a larger power, we return 5.
<pre>
<strong>Input:</strong> stations = [4,4,4,4], r = 0, k = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong>
<strong>Explanation:</strong>
It can be proved that we cannot make the minimum power of a city greater than 4.
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tags:
<strong>Explanation: </strong>You can do the following operations:
Operation 1: Select i = 1, so nums becomes [1,<strong><u>4</u></strong>,3,3,3]. Your score increases by 10.
Operation 2: Select i = 1, so nums becomes [1,<strong><u>2</u></strong>,3,3,3]. Your score increases by 4.
Operation 3: Select i = 2, so nums becomes [1,1,<u><strong>1</strong></u>,3,3]. Your score increases by 3.
Operation 3: Select i = 2, so nums becomes [1,2,<u><strong>1</strong></u>,3,3]. Your score increases by 3.
The final score is 10 + 4 + 3 = 17.
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tags:

<p>给你两个 <strong>正</strong>&nbsp;整数&nbsp;<code>x</code>&nbsp;和&nbsp;<code>y</code>&nbsp;,分别表示价值为 75 和 10 的硬币的数目。</p>

<p>Alice 和 Bob 正在玩一个游戏。每一轮中,Alice&nbsp;先进行操作,Bob 后操作。每次操作中,玩家需要拿出价值 <b>总和</b>&nbsp;为 115 的硬币。如果一名玩家无法执行此操作,那么这名玩家 <strong>输掉</strong>&nbsp;游戏。</p>
<p>Alice 和 Bob 正在玩一个游戏。每一轮中,Alice&nbsp;先进行操作,Bob 后操作。每次操作中,玩家需要拿走价值 <b>总和</b>&nbsp;为 115 的硬币。如果一名玩家无法执行此操作,那么这名玩家 <strong>输掉</strong>&nbsp;游戏。</p>

<p>两名玩家都采取 <strong>最优</strong>&nbsp;策略,请你返回游戏的赢家。</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tags:

<p>给你一个整数数组 <code>nums</code>。</p>

<p>请你统计所有满足一下条件的 <strong>非空</strong> <span data-keyword="subsequence-array">子序列</span> 对 <code>(seq1, seq2)</code> 的数量:</p>
<p>请你统计所有满足以下条件的 <strong>非空</strong> <span data-keyword="subsequence-array">子序列</span> 对 <code>(seq1, seq2)</code> 的数量:</p>

<ul>
<li>子序列 <code>seq1</code> 和 <code>seq2</code> <strong>不相交</strong>,意味着 <code>nums</code> 中 <strong>不存在 </strong>同时出现在两个序列中的下标。</li>
Expand Down
Loading
Loading