Skip to content

Commit

Permalink
feat: update lc problems (#3128)
Browse files Browse the repository at this point in the history
* feat: update lc problems

* docs: update readme
  • Loading branch information
yanglbme committed Jun 20, 2024
1 parent 46253d3 commit f74beb5
Show file tree
Hide file tree
Showing 53 changed files with 470 additions and 2 deletions.
10 changes: 9 additions & 1 deletion solution/2700-2799/2748.Number of Beautiful Pairs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ i = 0 和 j = 2 :nums[0] 的第一个数字是 1 ,nums[2] 的最后一个数

<!-- solution:start -->

### 方法一
### 方法一:计数

我们可以用一个长度为 $10$ 的数组 $\text{cnt}$ 来记录每个数字的第一个数字出现的次数。

遍历数组 $\text{nums}$,对于每个数字 $x$,我们枚举 $0$ 到 $9$ 的每个数字 $y$,如果 $\text{cnt}[y]$ 不为 $0$ 且 $\text{gcd}(x b\mod 10, y) = 1$,则答案加上 $\text{cnt}[y]$。然后,我们将 $x$ 的第一个数字出现的次数加 $1$。

遍历结束后,返回答案即可。

时间复杂度 $O(n \times (k + \log M))$,空间复杂度 $O(k + \log M)$。其中 $n$ 为数组 $\text{nums}$ 的长度,而 $k$ 和 $M$ 分别表示数组 $\text{nums}$ 中的数字的种类以及最大值。

<!-- tabs:start -->

Expand Down
10 changes: 9 additions & 1 deletion solution/2700-2799/2748.Number of Beautiful Pairs/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ Thus, we return 2.

<!-- solution:start -->

### Solution 1
### Solution 1: Counting

We can use an array $\text{cnt}$ of length $10$ to record the count of the first digit of each number.

Iterate through the array $\text{nums}$. For each number $x$, we enumerate each digit $y$ from $0$ to $9$. If $\text{cnt}[y]$ is not $0$ and $\text{gcd}(x \mod 10, y) = 1$, then the answer is incremented by $\text{cnt}[y]$. Then, we increment the count of the first digit of $x$ by $1$.

After the iteration, return the answer.

The time complexity is $O(n \times (k + \log M))$, and the space complexity is $O(k + \log M)$. Here, $n$ is the length of the array $\text{nums}$, while $k$ and $M$ respectively represent the number of distinct numbers and the maximum value in the array $\text{nums}$.

<!-- tabs:start -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3158.Find%20the%20XOR%20of%20Numbers%20Which%20Appear%20Twice/README.md
rating: 1172
source: 第 131 场双周赛 Q1
tags:
- 位运算
- 数组
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3158.Find%20the%20XOR%20of%20Numbers%20Which%20Appear%20Twice/README_EN.md
rating: 1172
source: Biweekly Contest 131 Q1
tags:
- Bit Manipulation
- Array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3159.Find%20Occurrences%20of%20an%20Element%20in%20an%20Array/README.md
rating: 1262
source: 第 131 场双周赛 Q2
tags:
- 数组
- 哈希表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3159.Find%20Occurrences%20of%20an%20Element%20in%20an%20Array/README_EN.md
rating: 1262
source: Biweekly Contest 131 Q2
tags:
- Array
- Hash Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3160.Find%20the%20Number%20of%20Distinct%20Colors%20Among%20the%20Balls/README.md
rating: 1517
source: 第 131 场双周赛 Q3
tags:
- 数组
- 哈希表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3160.Find%20the%20Number%20of%20Distinct%20Colors%20Among%20the%20Balls/README_EN.md
rating: 1517
source: Biweekly Contest 131 Q3
tags:
- Array
- Hash Table
Expand Down
2 changes: 2 additions & 0 deletions solution/3100-3199/3161.Block Placement Queries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3161.Block%20Placement%20Queries/README.md
rating: 2513
source: 第 131 场双周赛 Q4
tags:
- 树状数组
- 线段树
Expand Down
2 changes: 2 additions & 0 deletions solution/3100-3199/3161.Block Placement Queries/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3161.Block%20Placement%20Queries/README_EN.md
rating: 2513
source: Biweekly Contest 131 Q4
tags:
- Binary Indexed Tree
- Segment Tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3162.Find%20the%20Number%20of%20Good%20Pairs%20I/README.md
rating: 1168
source: 第 399 场周赛 Q1
tags:
- 数组
- 哈希表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3162.Find%20the%20Number%20of%20Good%20Pairs%20I/README_EN.md
rating: 1168
source: Weekly Contest 399 Q1
tags:
- Array
- Hash Table
Expand Down
2 changes: 2 additions & 0 deletions solution/3100-3199/3163.String Compression III/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3163.String%20Compression%20III/README.md
rating: 1311
source: 第 399 场周赛 Q2
tags:
- 字符串
---
Expand Down
2 changes: 2 additions & 0 deletions solution/3100-3199/3163.String Compression III/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3163.String%20Compression%20III/README_EN.md
rating: 1311
source: Weekly Contest 399 Q2
tags:
- String
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3164.Find%20the%20Number%20of%20Good%20Pairs%20II/README.md
rating: 1777
source: 第 399 场周赛 Q3
tags:
- 数组
- 哈希表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3164.Find%20the%20Number%20of%20Good%20Pairs%20II/README_EN.md
rating: 1777
source: Weekly Contest 399 Q3
tags:
- Array
- Hash Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3165.Maximum%20Sum%20of%20Subsequence%20With%20Non-adjacent%20Elements/README.md
rating: 2697
source: 第 399 场周赛 Q4
tags:
- 线段树
- 数组
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3165.Maximum%20Sum%20of%20Subsequence%20With%20Non-adjacent%20Elements/README_EN.md
rating: 2697
source: Weekly Contest 399 Q4
tags:
- Segment Tree
- Array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3168.Minimum%20Number%20of%20Chairs%20in%20a%20Waiting%20Room/README.md
rating: 1211
source: 第 400 场周赛 Q1
tags:
- 字符串
- 模拟
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3168.Minimum%20Number%20of%20Chairs%20in%20a%20Waiting%20Room/README_EN.md
rating: 1211
source: Weekly Contest 400 Q1
tags:
- String
- Simulation
Expand Down
2 changes: 2 additions & 0 deletions solution/3100-3199/3169.Count Days Without Meetings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3169.Count%20Days%20Without%20Meetings/README.md
rating: 1483
source: 第 400 场周赛 Q2
tags:
- 数组
- 排序
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3169.Count%20Days%20Without%20Meetings/README_EN.md
rating: 1483
source: Weekly Contest 400 Q2
tags:
- Array
- Sorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3170.Lexicographically%20Minimum%20String%20After%20Removing%20Stars/README.md
rating: 1772
source: 第 400 场周赛 Q3
tags:
-
- 贪心
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3170.Lexicographically%20Minimum%20String%20After%20Removing%20Stars/README_EN.md
rating: 1772
source: Weekly Contest 400 Q3
tags:
- Stack
- Greedy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3171.Find%20Subarray%20With%20Bitwise%20OR%20Closest%20to%20K/README.md
rating: 2162
source: 第 400 场周赛 Q4
tags:
- 位运算
- 线段树
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3171.Find%20Subarray%20With%20Bitwise%20OR%20Closest%20to%20K/README_EN.md
rating: 2162
source: Weekly Contest 400 Q4
tags:
- Bit Manipulation
- Segment Tree
Expand Down
2 changes: 2 additions & 0 deletions solution/3100-3199/3174.Clear Digits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3174.Clear%20Digits/README.md
rating: 1255
source: 第 132 场双周赛 Q1
tags:
- 哈希表
- 字符串
Expand Down
2 changes: 2 additions & 0 deletions solution/3100-3199/3174.Clear Digits/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3174.Clear%20Digits/README_EN.md
rating: 1255
source: Biweekly Contest 132 Q1
tags:
- Hash Table
- String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3175.Find%20The%20First%20Player%20to%20win%20K%20Games%20in%20a%20Row/README.md
rating: 1488
source: 第 132 场双周赛 Q2
tags:
- 数组
- 模拟
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3175.Find%20The%20First%20Player%20to%20win%20K%20Games%20in%20a%20Row/README_EN.md
rating: 1488
source: Biweekly Contest 132 Q2
tags:
- Array
- Simulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3176.Find%20the%20Maximum%20Length%20of%20a%20Good%20Subsequence%20I/README.md
rating: 1849
source: 第 132 场双周赛 Q3
tags:
- 数组
- 哈希表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3176.Find%20the%20Maximum%20Length%20of%20a%20Good%20Subsequence%20I/README_EN.md
rating: 1849
source: Biweekly Contest 132 Q3
tags:
- Array
- Hash Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3177.Find%20the%20Maximum%20Length%20of%20a%20Good%20Subsequence%20II/README.md
rating: 2364
source: 第 132 场双周赛 Q4
tags:
- 数组
- 哈希表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3177.Find%20the%20Maximum%20Length%20of%20a%20Good%20Subsequence%20II/README_EN.md
rating: 2364
source: Biweekly Contest 132 Q4
tags:
- Array
- Hash Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3178.Find%20the%20Child%20Who%20Has%20the%20Ball%20After%20K%20Seconds/README.md
rating: 1255
source: 第 401 场周赛 Q1
tags:
- 数学
- 模拟
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3178.Find%20the%20Child%20Who%20Has%20the%20Ball%20After%20K%20Seconds/README_EN.md
rating: 1255
source: Weekly Contest 401 Q1
tags:
- Math
- Simulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3179.Find%20the%20N-th%20Value%20After%20K%20Seconds/README.md
rating: 1369
source: 第 401 场周赛 Q2
tags:
- 数组
- 数学
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3179.Find%20the%20N-th%20Value%20After%20K%20Seconds/README_EN.md
rating: 1369
source: Weekly Contest 401 Q2
tags:
- Array
- Math
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3180.Maximum%20Total%20Reward%20Using%20Operations%20I/README.md
rating: 1848
source: 第 401 场周赛 Q3
tags:
- 数组
- 动态规划
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3180.Maximum%20Total%20Reward%20Using%20Operations%20I/README_EN.md
rating: 1848
source: Weekly Contest 401 Q3
tags:
- Array
- Dynamic Programming
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3181.Maximum%20Total%20Reward%20Using%20Operations%20II/README.md
rating: 2688
source: 第 401 场周赛 Q4
tags:
- 位运算
- 数组
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3181.Maximum%20Total%20Reward%20Using%20Operations%20II/README_EN.md
rating: 2688
source: Weekly Contest 401 Q4
tags:
- Bit Manipulation
- Array
Expand Down
Loading

0 comments on commit f74beb5

Please sign in to comment.