Skip to content

Commit 7470b06

Browse files
committed
feat: add solutions to lc problems: No.2032~2035
1 parent 4b8d1ae commit 7470b06

File tree

33 files changed

+2782
-1024
lines changed

33 files changed

+2782
-1024
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# [2026. Low-Quality Problems](https://leetcode-cn.com/problems/low-quality-problems)
2+
3+
[English Version](/solution/2000-2099/2026.Low-Quality%20Problems/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Problems</code></p>
10+
11+
<pre>
12+
+-------------+------+
13+
| Column Name | Type |
14+
+-------------+------+
15+
| problem_id | int |
16+
| likes | int |
17+
| dislikes | int |
18+
+-------------+------+
19+
problem_id is the primary key column for this table.
20+
Each row of this table indicates the number of likes and dislikes for a LeetCode problem.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Write an SQL query to report the IDs of the <strong>low-quality</strong> problems. A LeetCode problem is <strong>low-quality</strong> if the like percentage of the problem (number of likes divided by the total number of votes) is <strong>strictly less than</strong> <code>60%</code>.</p>
26+
27+
<p>Return the result table ordered by <code>problem_id</code> in ascending order.</p>
28+
29+
<p>The query result format is in the following example.</p>
30+
31+
<p>&nbsp;</p>
32+
<p><strong>Example 1:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong>
36+
Problems table:
37+
+------------+-------+----------+
38+
| problem_id | likes | dislikes |
39+
+------------+-------+----------+
40+
| 6 | 1290 | 425 |
41+
| 11 | 2677 | 8659 |
42+
| 1 | 4446 | 2760 |
43+
| 7 | 8569 | 6086 |
44+
| 13 | 2050 | 4164 |
45+
| 10 | 9002 | 7446 |
46+
+------------+-------+----------+
47+
<strong>Output:</strong>
48+
+------------+
49+
| problem_id |
50+
+------------+
51+
| 7 |
52+
| 10 |
53+
| 11 |
54+
| 13 |
55+
+------------+
56+
<strong>Explanation:</strong> The like percentages are as follows:
57+
- Problem 1: (4446 / (4446 + 2760)) * 100 = 61.69858%
58+
- Problem 6: (1290 / (1290 + 425)) * 100 = 75.21866%
59+
- Problem 7: (8569 / (8569 + 6086)) * 100 = 58.47151%
60+
- Problem 10: (9002 / (9002 + 7446)) * 100 = 54.73006%
61+
- Problem 11: (2677 / (2677 + 8659)) * 100 = 23.61503%
62+
- Problem 13: (2050 / (2050 + 4164)) * 100 = 32.99002%
63+
Problems 7, 10, 11, and 13 are low-quality problems because their like percentages are less than 60%.</pre>
64+
65+
## 解法
66+
67+
<!-- 这里可写通用的实现逻辑 -->
68+
69+
<!-- tabs:start -->
70+
71+
### **SQL**
72+
73+
<!-- 这里可写当前语言的特殊实现逻辑 -->
74+
75+
```sql
76+
77+
```
78+
79+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# [2026. Low-Quality Problems](https://leetcode.com/problems/low-quality-problems)
2+
3+
[中文文档](/solution/2000-2099/2026.Low-Quality%20Problems/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Problems</code></p>
8+
9+
<pre>
10+
+-------------+------+
11+
| Column Name | Type |
12+
+-------------+------+
13+
| problem_id | int |
14+
| likes | int |
15+
| dislikes | int |
16+
+-------------+------+
17+
problem_id is the primary key column for this table.
18+
Each row of this table indicates the number of likes and dislikes for a LeetCode problem.
19+
</pre>
20+
21+
<p>&nbsp;</p>
22+
23+
<p>Write an SQL query to report the IDs of the <strong>low-quality</strong> problems. A LeetCode problem is <strong>low-quality</strong> if the like percentage of the problem (number of likes divided by the total number of votes) is <strong>strictly less than</strong> <code>60%</code>.</p>
24+
25+
<p>Return the result table ordered by <code>problem_id</code> in ascending order.</p>
26+
27+
<p>The query result format is in the following example.</p>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Example 1:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong>
34+
Problems table:
35+
+------------+-------+----------+
36+
| problem_id | likes | dislikes |
37+
+------------+-------+----------+
38+
| 6 | 1290 | 425 |
39+
| 11 | 2677 | 8659 |
40+
| 1 | 4446 | 2760 |
41+
| 7 | 8569 | 6086 |
42+
| 13 | 2050 | 4164 |
43+
| 10 | 9002 | 7446 |
44+
+------------+-------+----------+
45+
<strong>Output:</strong>
46+
+------------+
47+
| problem_id |
48+
+------------+
49+
| 7 |
50+
| 10 |
51+
| 11 |
52+
| 13 |
53+
+------------+
54+
<strong>Explanation:</strong> The like percentages are as follows:
55+
- Problem 1: (4446 / (4446 + 2760)) * 100 = 61.69858%
56+
- Problem 6: (1290 / (1290 + 425)) * 100 = 75.21866%
57+
- Problem 7: (8569 / (8569 + 6086)) * 100 = 58.47151%
58+
- Problem 10: (9002 / (9002 + 7446)) * 100 = 54.73006%
59+
- Problem 11: (2677 / (2677 + 8659)) * 100 = 23.61503%
60+
- Problem 13: (2050 / (2050 + 4164)) * 100 = 32.99002%
61+
Problems 7, 10, 11, and 13 are low-quality problems because their like percentages are less than 60%.</pre>
62+
63+
## Solutions
64+
65+
<!-- tabs:start -->
66+
67+
### **SQL**
68+
69+
```sql
70+
71+
```
72+
73+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# [2032. 至少在两个数组中出现的值](https://leetcode-cn.com/problems/two-out-of-three)
2+
3+
[English Version](/solution/2000-2099/2032.Two%20Out%20of%20Three/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
给你三个整数数组 <code>nums1</code>、<code>nums2</code> 和 <code>nums3</code> ,请你构造并返回一个 <strong>不同</strong> 数组,且由 <strong>至少</strong> 在 <strong>两个</strong> 数组中出现的所有值组成<em>。</em>数组中的元素可以按 <strong>任意</strong> 顺序排列。
10+
11+
<p>&nbsp;</p>
12+
13+
<p><strong>示例 1:</strong></p>
14+
15+
<pre><strong>输入:</strong>nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]
16+
<strong>输出:</strong>[3,2]
17+
<strong>解释:</strong>至少在两个数组中出现的所有值为:
18+
- 3 ,在全部三个数组中都出现过。
19+
- 2 ,在数组 nums1 和 nums2 中出现过。
20+
</pre>
21+
22+
<p><strong>示例 2:</strong></p>
23+
24+
<pre><strong>输入:</strong>nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]
25+
<strong>输出:</strong>[2,3,1]
26+
<strong>解释:</strong>至少在两个数组中出现的所有值为:
27+
- 2 ,在数组 nums2 和 nums3 中出现过。
28+
- 3 ,在数组 nums1 和 nums2 中出现过。
29+
- 1 ,在数组 nums1 和 nums3 中出现过。
30+
</pre>
31+
32+
<p><strong>示例 3:</strong></p>
33+
34+
<pre><strong>输入:</strong>nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]
35+
<strong>输出:</strong>[]
36+
<strong>解释:</strong>不存在至少在两个数组中出现的值。
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
41+
<p><strong>提示:</strong></p>
42+
43+
<ul>
44+
<li><code>1 &lt;= nums1.length, nums2.length, nums3.length &lt;= 100</code></li>
45+
<li><code>1 &lt;= nums1[i], nums2[j], nums3[k] &lt;= 100</code></li>
46+
</ul>
47+
48+
## 解法
49+
50+
<!-- 这里可写通用的实现逻辑 -->
51+
52+
<!-- tabs:start -->
53+
54+
### **Python3**
55+
56+
<!-- 这里可写当前语言的特殊实现逻辑 -->
57+
58+
```python
59+
class Solution:
60+
def twoOutOfThree(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:
61+
s1, s2, s3 = set(nums1), set(nums2), set(nums3)
62+
ans = []
63+
for i in range(1, 101):
64+
a, b, c = i in s1, i in s2, i in s3
65+
if a + b + c > 1:
66+
ans.append(i)
67+
return ans
68+
```
69+
70+
### **Java**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```java
75+
class Solution {
76+
public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
77+
List<Integer> ans = new ArrayList<>();
78+
Set<Integer> s1 = get(nums1);
79+
Set<Integer> s2 = get(nums2);
80+
Set<Integer> s3 = get(nums3);
81+
for (int i = 1; i <= 100; ++i) {
82+
int a = s1.contains(i) ? 1 : 0;
83+
int b = s2.contains(i) ? 1 : 0;
84+
int c = s3.contains(i) ? 1 : 0;
85+
if (a + b + c > 1) {
86+
ans.add(i);
87+
}
88+
}
89+
return ans;
90+
}
91+
92+
private Set<Integer> get(int[] nums) {
93+
Set<Integer> s = new HashSet<>();
94+
for (int num : nums) {
95+
s.add(num);
96+
}
97+
return s;
98+
}
99+
}
100+
```
101+
102+
### **C++**
103+
104+
```cpp
105+
class Solution {
106+
public:
107+
vector<int> twoOutOfThree(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3) {
108+
auto s1 = get(nums1), s2 = get(nums2), s3 = get(nums3);
109+
vector<int> ans;
110+
for (int i = 1; i <= 100; ++i)
111+
{
112+
int a = s1.count(i) ? 1 : 0;
113+
int b = s2.count(i) ? 1 : 0;
114+
int c = s3.count(i) ? 1 : 0;
115+
if (a + b + c > 1) ans.push_back(i);
116+
}
117+
return ans;
118+
}
119+
120+
unordered_set<int> get(vector<int>& nums) {
121+
unordered_set<int> s;
122+
for (int num : nums) s.insert(num);
123+
return s;
124+
}
125+
};
126+
```
127+
128+
### **Go**
129+
130+
```go
131+
func twoOutOfThree(nums1 []int, nums2 []int, nums3 []int) []int {
132+
s1, s2, s3 := get(nums1), get(nums2), get(nums3)
133+
var ans []int
134+
for i := 1; i <= 100; i++ {
135+
a, b, c := 0, 0, 0
136+
if s1[i] {
137+
a++
138+
}
139+
if s2[i] {
140+
b++
141+
}
142+
if s3[i] {
143+
c++
144+
}
145+
if a+b+c > 1 {
146+
ans = append(ans, i)
147+
}
148+
}
149+
return ans
150+
}
151+
152+
func get(nums []int) map[int]bool {
153+
s := make(map[int]bool, 101)
154+
for _, num := range nums {
155+
s[num] = true
156+
}
157+
return s
158+
}
159+
```
160+
161+
### **...**
162+
163+
```
164+
165+
```
166+
167+
<!-- tabs:end -->

0 commit comments

Comments
 (0)