Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the LeetCode 1861 solution set by adding TypeScript and Rust implementations, while syncing the existing multilingual code snippets and explanations with the problem’s boxGrid naming.
Changes:
- Added new TypeScript and Rust solutions for LC 1861 using the same rotate-then-fall simulation approach as the existing implementations.
- Renamed parameters in the existing Python, Java, C++, and Go solutions from
boxtoboxGridfor consistency with the problem statement. - Expanded the Chinese and English READMEs with a fuller queue-based explanation and added TypeScript/Rust code tabs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| solution/1800-1899/1861.Rotating the Box/Solution.ts | Adds the new TypeScript implementation. |
| solution/1800-1899/1861.Rotating the Box/Solution.rs | Adds the new Rust implementation. |
| solution/1800-1899/1861.Rotating the Box/Solution.py | Renames the input variable and normalizes character literals. |
| solution/1800-1899/1861.Rotating the Box/Solution.java | Renames the input variable to match the problem statement. |
| solution/1800-1899/1861.Rotating the Box/Solution.go | Renames the input variable to match the problem statement. |
| solution/1800-1899/1861.Rotating the Box/Solution.cpp | Renames the input variable to match the problem statement. |
| solution/1800-1899/1861.Rotating the Box/README.md | Updates the Chinese explanation and adds TS/Rust snippets. |
| solution/1800-1899/1861.Rotating the Box/README_EN.md | Updates the English explanation and adds TS/Rust snippets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+14
to
+20
| for (let i = n - 1; i >= 0; i--) { | ||
| if (ans[i][j] === '*') { | ||
| q.length = 0; | ||
| } else if (ans[i][j] === '.') { | ||
| q.push(i); | ||
| } else if (q.length > 0) { | ||
| const t = q.shift()!; |
| The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$. Where $m$ and $n$ are the number of rows and columns of the matrix, respectively. | ||
| Specifically, we use a queue $q$ to store the row indices of empty positions in the current column. When traversing each column, we scan from bottom to top. If we encounter a stone, we drop it to the first empty position in $q$, remove that empty position from $q$, and add the current position's row index to $q$ since it becomes empty. If we encounter an obstacle, we clear $q$ because stones cannot pass through obstacles. If we encounter an empty position, we add its row index to $q$. | ||
|
|
||
| The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows and columns of the matrix respectively. |
|
|
||
| 具体地,我们使用一个队列 $q$ 来存储当前列中空位置的行号。遍历每一列,我们从下往上扫描,如果遇到一个石头,我们就将它掉落到 $q$ 中第一个空位置,并将这个空位置从 $q$ 中移除,由于当前位置变成了空位置,我们就将它的行号加入 $q$ 中;如果遇到一个障碍物,我们就清空 $q$,因为石头无法穿过障碍物;如果遇到一个空位置,我们就将它的行号加入 $q$ 中。 | ||
|
|
||
| 时间复杂度 $O(m \times n)$,空间复杂度 $O(m \times n)$。其中 $m$ 和 $n$ 分别是矩阵的行数和列数。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.