Skip to content

Commit e4f067f

Browse files
authored
feat: update lc problems (#2811)
1 parent 8f706c5 commit e4f067f

File tree

11 files changed

+51
-51
lines changed

11 files changed

+51
-51
lines changed

lcci/17.16.The Masseuse/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ class Solution {
124124
func massage(_ nums: [Int]) -> Int {
125125
var f = 0
126126
var g = 0
127-
127+
128128
for x in nums {
129129
let ff = g + x
130130
let gg = max(f, g)
131131
f = ff
132132
g = gg
133133
}
134-
134+
135135
return max(f, g)
136136
}
137137
}

lcci/17.16.The Masseuse/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ class Solution {
121121
func massage(_ nums: [Int]) -> Int {
122122
var f = 0
123123
var g = 0
124-
124+
125125
for x in nums {
126126
let ff = g + x
127127
let gg = max(f, g)
128128
f = ff
129129
g = gg
130130
}
131-
131+
132132
return max(f, g)
133133
}
134134
}

lcci/17.18.Shortest Supersequence/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ class Solution {
194194
var need = [Int: Int]()
195195
var window = [Int: Int]()
196196
small.forEach { need[$0, default: 0] += 1 }
197-
197+
198198
var count = needCount
199199
var minLength = Int.max
200200
var result = (-1, -1)
201-
201+
202202
var left = 0
203203
for right in 0..<big.count {
204204
let element = big[right]
@@ -208,13 +208,13 @@ class Solution {
208208
count -= 1
209209
}
210210
}
211-
211+
212212
while count == 0 {
213213
if right - left + 1 < minLength {
214214
minLength = right - left + 1
215215
result = (left, right)
216216
}
217-
217+
218218
let leftElement = big[left]
219219
if need[leftElement] != nil {
220220
window[leftElement]! -= 1
@@ -225,7 +225,7 @@ class Solution {
225225
left += 1
226226
}
227227
}
228-
228+
229229
return result.0 == -1 ? [] : [result.0, result.1]
230230
}
231231
}

lcci/17.18.Shortest Supersequence/README_EN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ class Solution {
198198
var need = [Int: Int]()
199199
var window = [Int: Int]()
200200
small.forEach { need[$0, default: 0] += 1 }
201-
201+
202202
var count = needCount
203203
var minLength = Int.max
204204
var result = (-1, -1)
205-
205+
206206
var left = 0
207207
for right in 0..<big.count {
208208
let element = big[right]
@@ -212,13 +212,13 @@ class Solution {
212212
count -= 1
213213
}
214214
}
215-
215+
216216
while count == 0 {
217217
if right - left + 1 < minLength {
218218
minLength = right - left + 1
219219
result = (left, right)
220220
}
221-
221+
222222
let leftElement = big[left]
223223
if need[leftElement] != nil {
224224
window[leftElement]! -= 1
@@ -229,7 +229,7 @@ class Solution {
229229
left += 1
230230
}
231231
}
232-
232+
233233
return result.0 == -1 ? [] : [result.0, result.1]
234234
}
235235
}

lcci/17.19.Missing Two/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -147,31 +147,31 @@ class Solution {
147147
func missingTwo(_ nums: [Int]) -> [Int] {
148148
let n = nums.count + 2
149149
var xor = 0
150-
150+
151151
for num in nums {
152152
xor ^= num
153153
}
154-
154+
155155
for i in 1...n {
156156
xor ^= i
157157
}
158-
158+
159159
let diff = xor & (-xor)
160-
160+
161161
var a = 0
162-
162+
163163
for num in nums {
164164
if (num & diff) != 0 {
165165
a ^= num
166166
}
167167
}
168-
168+
169169
for i in 1...n {
170170
if (i & diff) != 0 {
171171
a ^= i
172172
}
173173
}
174-
174+
175175
let b = xor ^ a
176176
return [a, b]
177177
}

lcci/17.19.Missing Two/README_EN.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -140,31 +140,31 @@ class Solution {
140140
func missingTwo(_ nums: [Int]) -> [Int] {
141141
let n = nums.count + 2
142142
var xor = 0
143-
143+
144144
for num in nums {
145145
xor ^= num
146146
}
147-
147+
148148
for i in 1...n {
149149
xor ^= i
150150
}
151-
151+
152152
let diff = xor & (-xor)
153-
153+
154154
var a = 0
155-
155+
156156
for num in nums {
157157
if (num & diff) != 0 {
158158
a ^= num
159159
}
160160
}
161-
161+
162162
for i in 1...n {
163163
if (i & diff) != 0 {
164164
a ^= i
165165
}
166166
}
167-
167+
168168
let b = xor ^ a
169169
return [a, b]
170170
}

solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
函数 $\text{dfs}(\text{mask}, \text{pre})$ 的计算过程如下:
6767

68-
- 如果 $\text{mask}$ 的二进制表示中 $1$ 的个数为 $n$,即 $\text{mask} = 2^n - 1$,表示所有数字都已经被选取,此时返回 $\text{abs}(\text{pre} - \text{nums}[0])$;
68+
- 如果 $\text{mask}$ 的二进制表示中 $1$ 的个数为 $n$,即 $\text{mask} = 2^n - 1$,表示所有数字都已经被选取,此时返回 $|\text{pre} - \text{nums}[0]|$;
6969
- 否则,我们枚举下一个选取的数字 $\text{cur}$,如果数字 $\text{cur}$ 还未被选取,那么我们可以将数字 $\text{cur}$ 加入到排列中,此时排列的分数为 $|\text{pre} - \text{nums}[\text{cur}]| + \text{dfs}(\text{mask} \, | \, 1 << \text{cur}, \text{cur})$,我们需要取所有 $\text{cur}$ 中分数的最小值。
7070

7171
最后,我们利用一个函数 $\text{g}(\text{mask}, \text{pre})$ 来构造得到最小分数的排列。我们首先将数字 $\text{pre}$ 加入到排列中,然后枚举下一个选取的数字 $\text{cur}$,如果数字 $\text{cur}$ 还未被选取,且满足 $|\text{pre} - \text{nums}[\text{cur}]| + \text{dfs}(\text{mask} \, | \, 1 << \text{cur}, \text{cur})$ 的值等于 $\text{dfs}(\text{mask}, \text{pre})$,那么我们就可以将数字 $\text{cur}$ 加入到排列中。

solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ We design a function $\text{dfs}(\text{mask}, \text{pre})$, which represents the
6161

6262
The calculation process of the function $\text{dfs}(\text{mask}, \text{pre})$ is as follows:
6363

64-
- If the number of $1$s in the binary representation of $\text{mask}$ is $n$, that is, $\text{mask} = 2^n - 1$, it means that all numbers have been selected, then return $\text{abs}(\text{pre} - \text{nums}[0])$;
64+
- If the number of $1$s in the binary representation of $\text{mask}$ is $n$, that is, $\text{mask} = 2^n - 1$, it means that all numbers have been selected, then return $|\text{pre} - \text{nums}[0]|$;
6565
- Otherwise, we enumerate the next selected number $\text{cur}$. If the number $\text{cur}$ has not been selected yet, then we can add the number $\text{cur}$ to the permutation. At this time, the score of the permutation is $|\text{pre} - \text{nums}[\text{cur}]| + \text{dfs}(\text{mask} \, | \, 1 << \text{cur}, \text{cur})$. We need to take the minimum score among all $\text{cur}$.
6666

6767
Finally, we use a function $\text{g}(\text{mask}, \text{pre})$ to construct the permutation that gets the minimum score. We first add the number $\text{pre}$ to the permutation, and then enumerate the next selected number $\text{cur}$. If the number $\text{cur}$ has not been selected yet, and it satisfies that the value of $|\text{pre} - \text{nums}[\text{cur}]| + \text{dfs}(\text{mask} \, | \, 1 << \text{cur}, \text{cur})$ is equal to $\text{dfs}(\text{mask}, \text{pre})$, then we can add the number $\text{cur}$ to the permutation.

solution/3100-3199/3150.Invalid Tweets II/README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [3150. Invalid Tweets II 🔒](https://leetcode.cn/problems/invalid-tweets-ii)
1+
# [3150. 无效的推文 II 🔒](https://leetcode.cn/problems/invalid-tweets-ii)
22

33
[English Version](/solution/3100-3199/3150.Invalid%20Tweets%20II/README_EN.md)
44

@@ -8,7 +8,7 @@
88

99
<!-- 这里写题目描述 -->
1010

11-
<p>Table: <code>Tweets</code></p>
11+
<p>表:<code>Tweets</code></p>
1212

1313
<pre>
1414
+----------------+---------+
@@ -17,29 +17,29 @@
1717
| tweet_id | int |
1818
| content | varchar |
1919
+----------------+---------+
20-
tweet_id is the primary key (column with unique values) for this table.
21-
This table contains all the tweets in a social media app.
22-
</pre>
20+
tweet_id 是这个表的主键(有不同值的列)。
21+
这个表包含某社交媒体 App 中所有的推文。</pre>
2322

24-
<p>Write a solution to find <strong>invalid tweets</strong>. A tweet is considered invalid if it meets <strong>any</strong> of the following criteria:</p>
23+
<p>编写一个解决方案来找到 <strong>无效的推文</strong>。如果一条推文满足下面 <strong>任一</strong>&nbsp;条件会被认为无效:</p>
2524

2625
<ul>
27-
<li>It exceeds <code>140</code> characters in length.</li>
28-
<li>It has more than <code>3</code> mentions.</li>
29-
<li>It includes more than <code><font face="monospace">3</font></code>&nbsp;hashtags.</li>
26+
<li>长度超过&nbsp;<code>140</code>&nbsp;个字符。</li>
27+
<li>有超过&nbsp;<code>3</code>&nbsp;次提及。</li>
28+
<li>有超过&nbsp;<code><font face="monospace">3</font></code>&nbsp;个标签。</li>
3029
</ul>
3130

32-
<p>Return <em>the result table ordered by</em> <code>tweet_id</code> <em>in <strong>ascending</strong> order</em>.</p>
31+
<p>&nbsp;<code>tweet_id</code> <em><strong>升序</strong>&nbsp;</em>返回结果表。</p>
3332

34-
<p>The result format is in the following example.</p>
33+
<p>查询结果格式如下所示:</p>
3534

3635
<p>&nbsp;</p>
37-
<p><strong>Example:</strong></p>
36+
37+
<p><strong>示例:</strong></p>
3838

3939
<div class="example-block">
40-
<p><strong>Input:</strong></p>
40+
<p><b>输入:</b></p>
4141

42-
<p>Tweets table:</p>
42+
<p>Tweets 表:</p>
4343

4444
<pre class="example-io">
4545
+----------+-----------------------------------------------------------------------------------+
@@ -52,7 +52,7 @@ This table contains all the tweets in a social media app.
5252
+----------+-----------------------------------------------------------------------------------+
5353
</pre>
5454

55-
<p><strong>Output:</strong></p>
55+
<p><strong>输出:</strong></p>
5656

5757
<pre class="example-io">
5858
+----------+
@@ -63,13 +63,13 @@ This table contains all the tweets in a social media app.
6363
+----------+
6464
</pre>
6565

66-
<p><strong>Explanation:</strong></p>
66+
<p><strong>解释:</strong></p>
6767

6868
<ul>
69-
<li>tweet_id&nbsp;1 contains 4&nbsp;mentions.</li>
70-
<li>tweet_id 4 contains 4 hashtags.</li>
69+
<li>tweet_id&nbsp;1 包含 4&nbsp;次提及。</li>
70+
<li>tweet_id 4 包含 4 个标签。</li>
7171
</ul>
72-
Output table is ordered by tweet_id in ascending order.</div>
72+
输出表以 tweet_id 升序排序。</div>
7373

7474
## 解法
7575

solution/DATABASE_README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
| 3124 | [查找最长的电话](/solution/3100-3199/3124.Find%20Longest%20Calls/README.md) | `数据库` | 中等 | 🔒 |
279279
| 3126 | [Server Utilization Time](/solution/3100-3199/3126.Server%20Utilization%20Time/README.md) | `数据库` | 中等 | 🔒 |
280280
| 3140 | [连续空余座位 II](/solution/3100-3199/3140.Consecutive%20Available%20Seats%20II/README.md) | `数据库` | 中等 | 🔒 |
281-
| 3150 | [Invalid Tweets II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 |
281+
| 3150 | [无效的推文 II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 |
282282

283283
## 版权
284284

solution/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3160,7 +3160,7 @@
31603160
| 3147 | [从魔法师身上吸取的最大能量](/solution/3100-3199/3147.Taking%20Maximum%20Energy%20From%20the%20Mystic%20Dungeon/README.md) | | 中等 | 第 397 场周赛 |
31613161
| 3148 | [矩阵中的最大得分](/solution/3100-3199/3148.Maximum%20Difference%20Score%20in%20a%20Grid/README.md) | | 中等 | 第 397 场周赛 |
31623162
| 3149 | [找出分数最低的排列](/solution/3100-3199/3149.Find%20the%20Minimum%20Cost%20Array%20Permutation/README.md) | | 困难 | 第 397 场周赛 |
3163-
| 3150 | [Invalid Tweets II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 |
3163+
| 3150 | [无效的推文 II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 |
31643164

31653165
## 版权
31663166

0 commit comments

Comments
 (0)