Skip to content

Commit 085570c

Browse files
authored
feat: add solutions to lc problems: No.1690,1727,1730,1733 (#2302)
1 parent 0980c36 commit 085570c

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

solution/1600-1699/1690.Stone Game VII/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,6 @@ function stoneGameVII(stones: number[]): number {
304304
}
305305
```
306306

307+
<!-- tabs:end -->
308+
307309
<!-- end -->

solution/1700-1799/1727.Largest Submatrix With Rearrangements/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272
对于矩阵的某一行,我们记第 $k$ 大元素的值为 $val_k$,其中 $k \geq 1$,那么该行至少有 $k$ 个元素不小于 $val_k$,组成的全 $1$ 子矩阵面积为 $val_k \times k$。从大到小遍历矩阵该行的每个元素,取 $val_k \times k$ 的最大值,更新答案。
7373

74-
时间复杂度 $O(m\times n\times \log n)$。其中 $m$ 和 $n$ 分别为矩阵的行数和列数。
74+
时间复杂度 $O(m \times n \times \log n)$。其中 $m$ 和 $n$ 分别为矩阵的行数和列数。
7575

7676
<!-- tabs:start -->
7777

solution/1700-1799/1727.Largest Submatrix With Rearrangements/README_EN.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ The largest submatrix of 1s, in bold, has an area of 3.
4747

4848
## Solutions
4949

50-
### Solution 1
50+
### Solution 1: Preprocessing + Sorting
51+
52+
Since the matrix is rearranged by columns according to the problem, we can first preprocess each column of the matrix.
53+
54+
For each element with a value of $1$, we update its value to the maximum consecutive number of $1$s above it, that is, $matrix[i][j] = matrix[i-1][j] + 1$.
55+
56+
Next, we can sort each row of the updated matrix. Then traverse each row, calculate the area of the largest sub-matrix full of $1$s with this row as the bottom edge. The specific calculation logic is as follows:
57+
58+
For a row of the matrix, we denote the value of the $k$-th largest element as $val_k$, where $k \geq 1$, then there are at least $k$ elements in this row that are not less than $val_k$, forming a sub-matrix full of $1$s with an area of $val_k \times k$. Traverse each element of this row from large to small, take the maximum value of $val_k \times k$, and update the answer.
59+
60+
The time complexity is $O(m \times n \times \log n)$. Here, $m$ and $n$ are the number of rows and columns of the matrix, respectively.
5161

5262
<!-- tabs:start -->
5363

solution/1700-1799/1730.Shortest Path to Get Food/README_EN.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@
5656

5757
## Solutions
5858

59-
### Solution 1
59+
### Solution 1: BFS (Breadth-First Search)
60+
61+
According to the problem, we need to start from `*`, find the nearest `#`, and return the shortest path length.
62+
63+
First, we traverse the entire two-dimensional array to find the position of `*`, which will be the starting point for BFS, and put it into the queue.
64+
65+
Then, we start BFS, traversing the elements in the queue. Each time we traverse an element, we add the elements in the four directions (up, down, left, and right) of it into the queue, until we encounter `#`, and return the current layer number.
66+
67+
The time complexity is $O(m \times n)$, and the space complexity is $O(1)$. Here, $m$ and $n$ are the number of rows and columns of the two-dimensional array, respectively.
6068

6169
<!-- tabs:start -->
6270

solution/1700-1799/1733.Minimum Number of People to Teach/README_EN.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ Note that friendships are not transitive, meaning if <code>x</code> is a friend
5050

5151
## Solutions
5252

53-
### Solution 1
53+
### Solution 1: Simulation + Statistics
54+
55+
For each friendship, if the sets of languages known by the two people do not intersect, then a language needs to be taught so that the two people can communicate with each other. We put these people into a hash set $s$.
56+
57+
Then in this set $s$, we count the number of people who know each language, and get the maximum number, which we denote as $mx$. So the answer is `len(s) - mx`.
58+
59+
The time complexity is $O(m^2 \times k)$. Here, $m$ is the number of languages, and $k$ is the number of friendships.
5460

5561
<!-- tabs:start -->
5662

0 commit comments

Comments
 (0)