Skip to content

feat: add solutions for lc No.1861#5188

Merged
yanglbme merged 1 commit intomainfrom
dev
May 6, 2026
Merged

feat: add solutions for lc No.1861#5188
yanglbme merged 1 commit intomainfrom
dev

Conversation

@yanglbme
Copy link
Copy Markdown
Member

@yanglbme yanglbme commented May 6, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 6, 2026 00:21
@idoocs idoocs added cpp Issues or Pull requests relate to .cpp code core team Issues or pull requests from core team go Issues or Pull requests relate to .go code java Issues or Pull requests relate to .java code md Issues or Pull requests relate to .md files py Issues or Pull requests relate to .py code rs Issues or Pull requests relate to .rs code ts Issues or Pull requests relate to .ts code labels May 6, 2026
@yanglbme yanglbme merged commit 43f4d13 into main May 6, 2026
17 checks passed
@yanglbme yanglbme deleted the dev branch May 6, 2026 00:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 box to boxGrid for 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$ 分别是矩阵的行数和列数。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core team Issues or pull requests from core team cpp Issues or Pull requests relate to .cpp code go Issues or Pull requests relate to .go code java Issues or Pull requests relate to .java code md Issues or Pull requests relate to .md files py Issues or Pull requests relate to .py code rs Issues or Pull requests relate to .rs code ts Issues or Pull requests relate to .ts code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants