From c4643dead75acbc8625754636aa6a947b367a5ec Mon Sep 17 00:00:00 2001 From: yanglbme Date: Tue, 14 May 2024 10:58:14 +0800 Subject: [PATCH] feat: update lc problems --- lcci/17.16.The Masseuse/README.md | 4 +- lcci/17.16.The Masseuse/README_EN.md | 4 +- lcci/17.18.Shortest Supersequence/README.md | 10 ++--- .../17.18.Shortest Supersequence/README_EN.md | 10 ++--- lcci/17.19.Missing Two/README.md | 14 +++---- lcci/17.19.Missing Two/README_EN.md | 14 +++---- .../README.md | 2 +- .../README_EN.md | 2 +- .../3150.Invalid Tweets II/README.md | 38 +++++++++---------- solution/DATABASE_README.md | 2 +- solution/README.md | 2 +- 11 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lcci/17.16.The Masseuse/README.md b/lcci/17.16.The Masseuse/README.md index 2ac6e20444ef1..754c4df61333c 100644 --- a/lcci/17.16.The Masseuse/README.md +++ b/lcci/17.16.The Masseuse/README.md @@ -124,14 +124,14 @@ class Solution { func massage(_ nums: [Int]) -> Int { var f = 0 var g = 0 - + for x in nums { let ff = g + x let gg = max(f, g) f = ff g = gg } - + return max(f, g) } } diff --git a/lcci/17.16.The Masseuse/README_EN.md b/lcci/17.16.The Masseuse/README_EN.md index 76ffd8b9e0d01..abc72da1aadb5 100644 --- a/lcci/17.16.The Masseuse/README_EN.md +++ b/lcci/17.16.The Masseuse/README_EN.md @@ -121,14 +121,14 @@ class Solution { func massage(_ nums: [Int]) -> Int { var f = 0 var g = 0 - + for x in nums { let ff = g + x let gg = max(f, g) f = ff g = gg } - + return max(f, g) } } diff --git a/lcci/17.18.Shortest Supersequence/README.md b/lcci/17.18.Shortest Supersequence/README.md index 875bcfe96467c..28b00be78a5be 100644 --- a/lcci/17.18.Shortest Supersequence/README.md +++ b/lcci/17.18.Shortest Supersequence/README.md @@ -194,11 +194,11 @@ class Solution { var need = [Int: Int]() var window = [Int: Int]() small.forEach { need[$0, default: 0] += 1 } - + var count = needCount var minLength = Int.max var result = (-1, -1) - + var left = 0 for right in 0.. [Int] { let n = nums.count + 2 var xor = 0 - + for num in nums { xor ^= num } - + for i in 1...n { xor ^= i } - + let diff = xor & (-xor) - + var a = 0 - + for num in nums { if (num & diff) != 0 { a ^= num } } - + for i in 1...n { if (i & diff) != 0 { a ^= i } } - + let b = xor ^ a return [a, b] } diff --git a/lcci/17.19.Missing Two/README_EN.md b/lcci/17.19.Missing Two/README_EN.md index 57839d0d5b15c..a0e9b2f179fd9 100644 --- a/lcci/17.19.Missing Two/README_EN.md +++ b/lcci/17.19.Missing Two/README_EN.md @@ -140,31 +140,31 @@ class Solution { func missingTwo(_ nums: [Int]) -> [Int] { let n = nums.count + 2 var xor = 0 - + for num in nums { xor ^= num } - + for i in 1...n { xor ^= i } - + let diff = xor & (-xor) - + var a = 0 - + for num in nums { if (num & diff) != 0 { a ^= num } } - + for i in 1...n { if (i & diff) != 0 { a ^= i } } - + let b = xor ^ a return [a, b] } diff --git a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md index dc34a153748f6..ac3162512833d 100644 --- a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md +++ b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README.md @@ -65,7 +65,7 @@ 函数 $\text{dfs}(\text{mask}, \text{pre})$ 的计算过程如下: -- 如果 $\text{mask}$ 的二进制表示中 $1$ 的个数为 $n$,即 $\text{mask} = 2^n - 1$,表示所有数字都已经被选取,此时返回 $\text{abs}(\text{pre} - \text{nums}[0])$; +- 如果 $\text{mask}$ 的二进制表示中 $1$ 的个数为 $n$,即 $\text{mask} = 2^n - 1$,表示所有数字都已经被选取,此时返回 $|\text{pre} - \text{nums}[0]|$; - 否则,我们枚举下一个选取的数字 $\text{cur}$,如果数字 $\text{cur}$ 还未被选取,那么我们可以将数字 $\text{cur}$ 加入到排列中,此时排列的分数为 $|\text{pre} - \text{nums}[\text{cur}]| + \text{dfs}(\text{mask} \, | \, 1 << \text{cur}, \text{cur})$,我们需要取所有 $\text{cur}$ 中分数的最小值。 最后,我们利用一个函数 $\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}$ 加入到排列中。 diff --git a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md index 837790f976f3a..2c90463a711f1 100644 --- a/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md +++ b/solution/3100-3199/3149.Find the Minimum Cost Array Permutation/README_EN.md @@ -61,7 +61,7 @@ We design a function $\text{dfs}(\text{mask}, \text{pre})$, which represents the The calculation process of the function $\text{dfs}(\text{mask}, \text{pre})$ is as follows: -- 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])$; +- 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]|$; - 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}$. 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. diff --git a/solution/3100-3199/3150.Invalid Tweets II/README.md b/solution/3100-3199/3150.Invalid Tweets II/README.md index 25bd5e269d9f2..d73ca5ba2670d 100644 --- a/solution/3100-3199/3150.Invalid Tweets II/README.md +++ b/solution/3100-3199/3150.Invalid Tweets II/README.md @@ -1,4 +1,4 @@ -# [3150. Invalid Tweets II 🔒](https://leetcode.cn/problems/invalid-tweets-ii) +# [3150. 无效的推文 II 🔒](https://leetcode.cn/problems/invalid-tweets-ii) [English Version](/solution/3100-3199/3150.Invalid%20Tweets%20II/README_EN.md) @@ -8,7 +8,7 @@ -

Table: Tweets

+

表:Tweets

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

Write a solution to find invalid tweets. A tweet is considered invalid if it meets any of the following criteria:

+

编写一个解决方案来找到 无效的推文。如果一条推文满足下面 任一 条件会被认为无效:

-

Return the result table ordered by tweet_id in ascending order.

+

以 tweet_id 升序 返回结果表。

-

The result format is in the following example.

+

查询结果格式如下所示:

 

-

Example:

+ +

示例:

-

Input:

+

输入:

-

Tweets table:

+

Tweets 表:

   +----------+-----------------------------------------------------------------------------------+
@@ -52,7 +52,7 @@ This table contains all the tweets in a social media app.
   +----------+-----------------------------------------------------------------------------------+
   
-

Output:

+

输出:

   +----------+
@@ -63,13 +63,13 @@ This table contains all the tweets in a social media app.
   +----------+
   
-

Explanation:

+

解释:

    -
  • tweet_id 1 contains 4 mentions.
  • -
  • tweet_id 4 contains 4 hashtags.
  • +
  • tweet_id 1 包含 4 次提及。
  • +
  • tweet_id 4 包含 4 个标签。
-Output table is ordered by tweet_id in ascending order.
+输出表以 tweet_id 升序排序。 ## 解法 diff --git a/solution/DATABASE_README.md b/solution/DATABASE_README.md index a35b92bb16b42..062a7fc3c6c37 100644 --- a/solution/DATABASE_README.md +++ b/solution/DATABASE_README.md @@ -278,7 +278,7 @@ | 3124 | [查找最长的电话](/solution/3100-3199/3124.Find%20Longest%20Calls/README.md) | `数据库` | 中等 | 🔒 | | 3126 | [Server Utilization Time](/solution/3100-3199/3126.Server%20Utilization%20Time/README.md) | `数据库` | 中等 | 🔒 | | 3140 | [连续空余座位 II](/solution/3100-3199/3140.Consecutive%20Available%20Seats%20II/README.md) | `数据库` | 中等 | 🔒 | -| 3150 | [Invalid Tweets II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 | +| 3150 | [无效的推文 II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 | ## 版权 diff --git a/solution/README.md b/solution/README.md index 80b3f1df013b0..c08a11c90bbd4 100644 --- a/solution/README.md +++ b/solution/README.md @@ -3160,7 +3160,7 @@ | 3147 | [从魔法师身上吸取的最大能量](/solution/3100-3199/3147.Taking%20Maximum%20Energy%20From%20the%20Mystic%20Dungeon/README.md) | | 中等 | 第 397 场周赛 | | 3148 | [矩阵中的最大得分](/solution/3100-3199/3148.Maximum%20Difference%20Score%20in%20a%20Grid/README.md) | | 中等 | 第 397 场周赛 | | 3149 | [找出分数最低的排列](/solution/3100-3199/3149.Find%20the%20Minimum%20Cost%20Array%20Permutation/README.md) | | 困难 | 第 397 场周赛 | -| 3150 | [Invalid Tweets II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 | +| 3150 | [无效的推文 II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | | 简单 | 🔒 | ## 版权