Skip to content

feat: add solutions for lc No.2751#5112

Merged
yanglbme merged 1 commit intomainfrom
dev
Mar 25, 2026
Merged

feat: add solutions for lc No.2751#5112
yanglbme merged 1 commit intomainfrom
dev

Conversation

@yanglbme
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings March 25, 2026 23:57
@idoocs idoocs added 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 js Issues or Pull requests relate to .js code md Issues or Pull requests relate to .md files py Issues or Pull requests relate to .py code ts Issues or Pull requests relate to .ts code labels Mar 25, 2026
@yanglbme yanglbme merged commit 3937339 into main Mar 25, 2026
16 of 17 checks passed
@yanglbme yanglbme deleted the dev branch March 25, 2026 23:58
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

Adds/updates multi-language solutions and documentation for LeetCode 2751 (Robot Collisions), standardizing implementations around a sorted-index + stack collision simulation.

Changes:

  • Refactors TS/JS/Java/Go/C++ solutions to a consistent “sorted indices + stack” collision loop and returns survivors with health > 0.
  • Simplifies Python implementation and aligns variable naming (idx, stk, ans) across languages.
  • Expands README (EN/ZH) with an explicit “Stack Simulation” approach description and updated code snippets.

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/2700-2799/2751.Robot Collisions/Solution.ts Refactors to sorted indices + stack simulation; simplifies survivor filtering.
solution/2700-2799/2751.Robot Collisions/Solution.py Simplifies implementation and returns survivors via filtering; removes type hints.
solution/2700-2799/2751.Robot Collisions/Solution.js Mirrors TS refactor with stack simulation and health > 0 filter.
solution/2700-2799/2751.Robot Collisions/Solution.java Refactors to Deque-based stack; simplifies indexing/sorting and final collection.
solution/2700-2799/2751.Robot Collisions/Solution.go Refactors to sorted indices + stack; renames locals and returns ans.
solution/2700-2799/2751.Robot Collisions/Solution.cpp Refactors to sorted indices + vector-as-stack; returns survivors.
solution/2700-2799/2751.Robot Collisions/README_EN.md Adds approach explanation; updates code snippets to match refactor.
solution/2700-2799/2751.Robot Collisions/README.md Adds Chinese approach explanation; updates code snippets to match refactor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
Integer[] idx = new Integer[n];
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (a, b) -> positions[a] - positions[b]);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The comparator positions[a] - positions[b] can overflow for large positions values, producing an incorrect sort order and therefore incorrect collision outcomes. Use Integer.compare(positions[a], positions[b]) (or Comparator.comparingInt(i -> positions[i])) to avoid overflow.

Suggested change
Arrays.sort(idx, (a, b) -> positions[a] - positions[b]);
Arrays.sort(idx, (a, b) -> Integer.compare(positions[a], positions[b]));

Copilot uses AI. Check for mistakes.
}
Integer[] idx = new Integer[n];
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (a, b) -> positions[a] - positions[b]);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The Java snippet uses positions[a] - positions[b] as a comparator, which can overflow and is not a safe example to document. Update the README snippet to use Integer.compare(positions[a], positions[b]) (or Comparator.comparingInt(...)) so the documentation matches a correct, overflow-safe implementation.

Suggested change
Arrays.sort(idx, (a, b) -> positions[a] - positions[b]);
Arrays.sort(idx, (a, b) -> Integer.compare(positions[a], positions[b]));

Copilot uses AI. Check for mistakes.
n = len(positions)
indices = list(range(n))
stack = []
def survivedRobotsHealths(self, positions, healths, directions):
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This change removes the previously-present type hints (List[int], str, return type). If this repository is keeping typed Python solutions (as the previous version suggests), consider restoring the annotations (and the relevant typing import) to improve readability and enable static checking.

Copilot uses AI. Check for mistakes.
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 js Issues or Pull requests relate to .js code md Issues or Pull requests relate to .md files py Issues or Pull requests relate to .py 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