Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e413997

Browse files
author
openset
committed
Add: new
1 parent f3f5293 commit e413997

File tree

13 files changed

+403
-9
lines changed

13 files changed

+403
-9
lines changed

‎README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1284">1284</span> | [Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix "转化为全零矩阵的最少反转次数") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) | Hard |
66+
| <span id="1283">1283</span> | [Find the Smallest Divisor Given a Threshold](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold "使结果不超过阈值的最小除数") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-the-smallest-divisor-given-a-threshold) | Medium |
67+
| <span id="1282">1282</span> | [Group the People Given the Group Size They Belong To](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to "用户分组") | [Go](https://github.com/openset/leetcode/tree/master/problems/group-the-people-given-the-group-size-they-belong-to) | Medium |
68+
| <span id="1281">1281</span> | [Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer "整数的各位积和之差") | [Go](https://github.com/openset/leetcode/tree/master/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | Easy |
69+
| <span id="1280">1280</span> | [Students and Examinations](https://leetcode.com/problems/students-and-examinations) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/students-and-examinations) | Easy |
6570
| <span id="1279">1279</span> | [Traffic Light Controlled Intersection](https://leetcode.com/problems/traffic-light-controlled-intersection) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/traffic-light-controlled-intersection) | Easy |
6671
| <span id="1278">1278</span> | [Palindrome Partitioning III](https://leetcode.com/problems/palindrome-partitioning-iii "分割回文串 III") | [Go](https://github.com/openset/leetcode/tree/master/problems/palindrome-partitioning-iii) | Hard |
6772
| <span id="1277">1277</span> | [Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones "统计全为 1 的正方形子矩阵") | [Go](https://github.com/openset/leetcode/tree/master/problems/count-square-submatrices-with-all-ones) | Medium |

‎internal/leetcode/question_translation.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ type qtDataType struct {
1717
}
1818

1919
type translationsType struct {
20-
Title string `json:"title"`
21-
Question questionIDType `json:"question"`
22-
TypeName string `json:"__typename"`
23-
}
24-
25-
type questionIDType struct {
20+
Title string `json:"title"`
2621
QuestionID string `json:"questionId"`
2722
TypeName string `json:"__typename"`
2823
}
@@ -32,7 +27,7 @@ func GetQuestionTranslation() (qt QuestionTranslationType) {
3227
jsonStr := `{
3328
"operationName": "getQuestionTranslation",
3429
"variables": {},
35-
"query": "query getQuestionTranslation($lang: String) {\n translations: allAppliedQuestionTranslations(lang: $lang) {\n title\n question {\n questionId\n __typename\n }\n __typename\n }\n}\n"
30+
"query": "query getQuestionTranslation($lang: String) {\n translations: allAppliedQuestionTranslations(lang: $lang) {\n title\n questionId\n __typename\n }\n}\n"
3631
}`
3732
graphQLRequest(graphQLCnURL, jsonStr, questionTranslationFile, 2, &qt)
3833
if qt.Data.Translations == nil {
@@ -47,7 +42,7 @@ func GetQuestionTranslation() (qt QuestionTranslationType) {
4742
func init() {
4843
translation := GetQuestionTranslation()
4944
for _, item := range translation.Data.Translations {
50-
id := item.Question.QuestionID
45+
id := item.QuestionID
5146
if id, err := strconv.Atoi(id); err == nil {
5247
translationSet[id] = item.Title
5348
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/group-the-people-given-the-group-size-they-belong-to "Group the People Given the Group Size They Belong To")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix")
11+
12+
## [1283. Find the Smallest Divisor Given a Threshold (Medium)](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold "使结果不超过阈值的最小除数")
13+
14+
<p>Given an array of integers <code>nums</code> and an integer <code>threshold</code>, we will choose a positive integer divisor and&nbsp;divide&nbsp;all the array by it and sum the result of the division. Find the <strong>smallest</strong> divisor such that the result mentioned above is less than&nbsp;or equal to <code>threshold</code>.</p>
15+
16+
<p>Each&nbsp;result of&nbsp;division is rounded&nbsp;to the nearest integer greater than or equal to that element.&nbsp;(For example: 7/3 = 3 and 10/2 = 5).</p>
17+
18+
<p>It is guaranteed that there will be an answer.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> nums = [1,2,5,9], threshold = 6
25+
<strong>Output:</strong> 5
26+
<strong>Explanation:</strong> We can get a sum to 17 (1+2+5+9) if the divisor is 1.
27+
If the divisor is 4 we can get a sum to 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2).
28+
</pre>
29+
30+
<p><strong>Example 2:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> nums = [2,3,5,7,11], threshold = 11
34+
<strong>Output:</strong> 3
35+
</pre>
36+
37+
<p><strong>Example 3:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> nums = [19], threshold = 5
41+
<strong>Output:</strong> 4
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>1 &lt;= nums.length &lt;= 5 * 10^4</code></li>
49+
<li><code>1 &lt;= nums[i] &lt;= 10^6</code></li>
50+
<li><code>nums.length &lt;=&nbsp;threshold &lt;= 10^6</code></li>
51+
</ul>
52+
53+
### Related Topics
54+
[[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)]
55+
56+
### Hints
57+
<details>
58+
<summary>Hint 1</summary>
59+
Examine every possible number for solution. Choose the largest of them.
60+
</details>
61+
62+
<details>
63+
<summary>Hint 2</summary>
64+
Use binary search to reduce the time complexity.
65+
</details>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/subtract-the-product-and-sum-of-digits-of-an-integer "Subtract the Product and Sum of Digits of an Integer")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/find-the-smallest-divisor-given-a-threshold "Find the Smallest Divisor Given a Threshold")
11+
12+
## [1282. Group the People Given the Group Size They Belong To (Medium)](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to "用户分组")
13+
14+
<p>There are <code>n</code> people whose <strong>IDs</strong> go from <code>0</code> to <code>n - 1</code> and each person belongs <strong>exactly</strong> to one&nbsp;group. Given the array&nbsp;<code>groupSizes</code> of length <code>n</code> telling the group size each person belongs to, return the groups there are and the people&#39;s&nbsp;<strong>IDs</strong> each group includes.</p>
15+
16+
<p>You can return any solution in any order and the same applies for IDs. Also, it is guaranteed that there exists at least one solution.&nbsp;</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> groupSizes = [3,3,3,3,3,1,3]
23+
<strong>Output:</strong> [[5],[0,1,2],[3,4,6]]
24+
<b>Explanation:</b>
25+
Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].
26+
</pre>
27+
28+
<p><strong>Example 2:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> groupSizes = [2,1,3,3,3,2]
32+
<strong>Output:</strong> [[1],[0,5],[2,3,4]]
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>groupSizes.length == n</code></li>
40+
<li><code>1 &lt;= n&nbsp;&lt;= 500</code></li>
41+
<li><code>1 &lt;=&nbsp;groupSizes[i] &lt;= n</code></li>
42+
</ul>
43+
44+
### Related Topics
45+
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
46+
47+
### Hints
48+
<details>
49+
<summary>Hint 1</summary>
50+
Put people's IDs with same groupSize into buckets, then split each bucket into groups.
51+
</details>
52+
53+
<details>
54+
<summary>Hint 2</summary>
55+
Greedy fill until you need a new group.
56+
</details>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-the-smallest-divisor-given-a-threshold "Find the Smallest Divisor Given a Threshold")
9+
10+
Next >
11+
12+
## [1284. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix (Hard)](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix "转化为全零矩阵的最少反转次数")
13+
14+
<p>Given a <code>m x n</code> binary matrix <code>mat</code>. In one step, you can choose one cell and flip it and all the four neighbours of it&nbsp;if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighboors if they share one edge.</p>
15+
16+
<p>Return the <em>minimum number of steps</em> required to convert <code>mat</code>&nbsp;to a zero matrix or <strong>-1</strong> if you cannot.</p>
17+
18+
<p>Binary matrix is a matrix with all cells equal to 0 or 1 only.</p>
19+
20+
<p>Zero matrix is a matrix with all cells equal to 0.</p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
24+
<img alt="" src="https://assets.leetcode.com/uploads/2019/11/28/matrix.png" style="width: 409px; height: 86px;" />
25+
<pre>
26+
<strong>Input:</strong> mat = [[0,0],[0,1]]
27+
<strong>Output:</strong> 3
28+
<strong>Explanation:</strong> One possible solution is to flip (1, 0) then (0, 1) and finally (1, 1) as shown.
29+
</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> mat = [[0]]
35+
<strong>Output:</strong> 0
36+
<strong>Explanation:</strong> Given matrix is a zero matrix. We don&#39;t need to change it.
37+
</pre>
38+
39+
<p><strong>Example 3:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> mat = [[1,1,1],[1,0,1],[0,0,0]]
43+
<strong>Output:</strong> 6
44+
</pre>
45+
46+
<p><strong>Example 4:</strong></p>
47+
48+
<pre>
49+
<strong>Input:</strong> mat = [[1,0,0],[1,0,0]]
50+
<strong>Output:</strong> -1
51+
<strong>Explanation:</strong> Given matrix can&#39;t be a zero matrix
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>m ==&nbsp;mat.length</code></li>
59+
<li><code>n ==&nbsp;mat[0].length</code></li>
60+
<li><code>1 &lt;= m&nbsp;&lt;= 3</code></li>
61+
<li><code>1 &lt;= n&nbsp;&lt;= 3</code></li>
62+
<li><code>mat[i][j]</code> is 0 or 1.</li>
63+
</ul>
64+
65+
### Related Topics
66+
[[Breadth-first Search](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)]
67+
68+
### Hints
69+
<details>
70+
<summary>Hint 1</summary>
71+
Flipping same index two times is like not flipping it at all. Each index can be flipped one time. Try all possible combinations. O(2^(n*m)).
72+
</details>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/traffic-light-controlled-intersection "Traffic Light Controlled Intersection")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/subtract-the-product-and-sum-of-digits-of-an-integer "Subtract the Product and Sum of Digits of an Integer")
11+
12+
## [1280. Students and Examinations (Easy)](https://leetcode.com/problems/students-and-examinations "")
13+
14+
<p>Table: <code>Students</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| student_id | int |
20+
| student_name | varchar |
21+
+---------------+---------+
22+
student_id is the primary key for this table.
23+
Each row of this table contains the ID and the name of one student in the school.
24+
</pre>
25+
26+
<p>Table: <code>Subjects</code></p>
27+
<pre>
28+
+--------------+---------+
29+
| Column Name | Type |
30+
+--------------+---------+
31+
| subject_name | varchar |
32+
+--------------+---------+
33+
subject_name is the primary key for this table.
34+
Each row of this table contains a name of one subject in the school.
35+
</pre>
36+
37+
<p>Table: <code>Examinations</code></p>
38+
<pre>
39+
+--------------+---------+
40+
| Column Name | Type |
41+
+--------------+---------+
42+
| student_id | int |
43+
| subject_name | varchar |
44+
+--------------+---------+
45+
There is no primary key for this table. It may contain duplicates.
46+
Each student from Students table takes every course from Subjects table.
47+
Each row of this table indicates that a student with ID student_id attended the exam of subject_name.
48+
</pre>
49+
50+
Write an SQL query to find the number of times each student attended each exam.
51+
52+
Order the result table by student_id and subject_name.
53+
54+
The query result format is in the following example:
55+
<pre>
56+
Students table:
57+
+------------+--------------+
58+
| student_id | student_name |
59+
+------------+--------------+
60+
| 1 | Alice |
61+
| 2 | Bob |
62+
| 13 | John |
63+
| 6 | Alex |
64+
+------------+--------------+
65+
Subjects table:
66+
+--------------+
67+
| subject_name |
68+
+--------------+
69+
| Math |
70+
| Physics |
71+
| Programming |
72+
+--------------+
73+
Examinations table:
74+
+------------+--------------+
75+
| student_id | subject_name |
76+
+------------+--------------+
77+
| 1 | Math |
78+
| 1 | Physics |
79+
| 1 | Programming |
80+
| 2 | Programming |
81+
| 1 | Physics |
82+
| 1 | Math |
83+
| 13 | Math |
84+
| 13 | Programming |
85+
| 13 | Physics |
86+
| 2 | Math |
87+
| 1 | Math |
88+
+------------+--------------+
89+
Result table:
90+
+------------+--------------+--------------+----------------+
91+
| student_id | student_name | subject_name | attended_exams |
92+
+------------+--------------+--------------+----------------+
93+
| 1 | Alice | Math | 3 |
94+
| 1 | Alice | Physics | 2 |
95+
| 1 | Alice | Programming | 1 |
96+
| 2 | Bob | Math | 1 |
97+
| 2 | Bob | Physics | 0 |
98+
| 2 | Bob | Programming | 1 |
99+
| 6 | Alex | Math | 0 |
100+
| 6 | Alex | Physics | 0 |
101+
| 6 | Alex | Programming | 0 |
102+
| 13 | John | Math | 1 |
103+
| 13 | John | Physics | 1 |
104+
| 13 | John | Programming | 1 |
105+
+------------+--------------+--------------+----------------+
106+
The result table should contain all students and all subjects.
107+
Alice attended Math exam 3 times, Physics exam 2 times and Programming exam 1 time.
108+
Bob attended Math exam 1 time, Programming exam 1 time and didn't attend the Physics exam.
109+
Alex didn't attend any exam.
110+
John attended Math exam 1 time, Physics exam 1 time and Programming exam 1 time.
111+
</pre>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Create table If Not Exists Students (student_id int, student_name varchar(20));
2+
Create table If Not Exists Subjects (subject_name varchar(20));
3+
Create table If Not Exists Examinations (student_id int, subject_name varchar(20));
4+
Truncate table Students;
5+
insert into Students (student_id, student_name) values ('1', 'Alice');
6+
insert into Students (student_id, student_name) values ('2', 'Bob');
7+
insert into Students (student_id, student_name) values ('13', 'John');
8+
insert into Students (student_id, student_name) values ('6', 'Alex');
9+
Truncate table Subjects;
10+
insert into Subjects (subject_name) values ('Math');
11+
insert into Subjects (subject_name) values ('Physics');
12+
insert into Subjects (subject_name) values ('Programming');
13+
Truncate table Examinations;
14+
insert into Examinations (student_id, subject_name) values ('1', 'Math');
15+
insert into Examinations (student_id, subject_name) values ('1', 'Physics');
16+
insert into Examinations (student_id, subject_name) values ('1', 'Programming');
17+
insert into Examinations (student_id, subject_name) values ('2', 'Programming');
18+
insert into Examinations (student_id, subject_name) values ('1', 'Physics');
19+
insert into Examinations (student_id, subject_name) values ('1', 'Math');
20+
insert into Examinations (student_id, subject_name) values ('13', 'Math');
21+
insert into Examinations (student_id, subject_name) values ('13', 'Programming');
22+
insert into Examinations (student_id, subject_name) values ('13', 'Physics');
23+
insert into Examinations (student_id, subject_name) values ('2', 'Math');
24+
insert into Examinations (student_id, subject_name) values ('1', 'Math');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /