Skip to content

feat: add solutions for lc No.2574#5120

Merged
yanglbme merged 2 commits intomainfrom
dev
Mar 28, 2026
Merged

feat: add solutions for lc No.2574#5120
yanglbme merged 2 commits intomainfrom
dev

Conversation

@yanglbme
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings March 27, 2026 23:58
@idoocs idoocs added c Issues or Pull requests relate to .c code 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 labels Mar 27, 2026
@yanglbme yanglbme merged commit e09f1fe into main Mar 28, 2026
5 of 6 checks passed
@yanglbme yanglbme deleted the dev branch March 28, 2026 00:00
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

Update and standardize LeetCode solution implementations by fixing naming inconsistencies for LC 2574 across languages, consolidating solution variants, and adding a Rust implementation for LC 2573 with corresponding documentation updates.

Changes:

  • Standardized leftRightDifference/left_right_difference naming across multiple LC 2574 language solutions and refreshed implementations.
  • Removed redundant LC 2574 alternate solution files (Solution2/Solution3) and updated READMEs accordingly.
  • Added Rust solution for LC 2573 (“Find the String with LCP”) and included it in both EN/ZH READMEs.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
solution/2500-2599/2574.Left and Right Sum Differences/Solution.ts Rename + minor implementation refresh (l/r sums).
solution/2500-2599/2574.Left and Right Sum Differences/Solution.rs Fix function name typo and simplify loop with preallocated output.
solution/2500-2599/2574.Left and Right Sum Differences/Solution.py Fix method name typo and align variable naming.
solution/2500-2599/2574.Left and Right Sum Differences/Solution.java Fix method name typo and adjust sum computation.
solution/2500-2599/2574.Left and Right Sum Differences/Solution.go Fix function name typo and switch to indexed output slice.
solution/2500-2599/2574.Left and Right Sum Differences/Solution.cpp Fix method name typo and output sizing.
solution/2500-2599/2574.Left and Right Sum Differences/Solution.c Fix function name typo and reorganize allocation/returnSize.
solution/2500-2599/2574.Left and Right Sum Differences/README_EN.md Update narrative + code snippets; remove extra solutions.
solution/2500-2599/2574.Left and Right Sum Differences/README.md Update narrative + code snippets; remove extra solutions.
solution/2500-2599/2574.Left and Right Sum Differences/Solution2.ts Removed alternate TS solution variant.
solution/2500-2599/2574.Left and Right Sum Differences/Solution2.rs Removed alternate Rust solution variant.
solution/2500-2599/2574.Left and Right Sum Differences/Solution3.rs Removed alternate Rust solution variant.
solution/2500-2599/2573.Find the String with LCP/Solution.rs Added Rust solution implementation for LC 2573.
solution/2500-2599/2573.Find the String with LCP/README_EN.md Added Rust snippet + minor formatting cleanup.
solution/2500-2599/2573.Find the String with LCP/README.md Added Rust snippet + minor formatting cleanup.

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

Comment on lines +1 to +3
impl Solution {
pub fn find_the_string(lcp: Vec<Vec<i32>>) -> String {
let n = lcp.len();
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The PR title references adding solutions for LC 2574, but this PR also adds a new Rust solution for LC 2573 and updates its documentation. Please update the PR title (or description) to reflect LC 2573 additions and the LC 2574 consolidation/renaming so the change scope is accurately represented.

Copilot uses AI. Check for mistakes.
l += x;
}
return ans;
}
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The TypeScript snippet ends with } here, while the actual Solution.ts ends the function with };. Either form parses, but the docs should match the repository solution exactly to avoid confusion when copying (suggest aligning the README_EN snippet with Solution.ts).

Suggested change
}
};

Copilot uses AI. Check for mistakes.
let left = 0,
right = nums.reduce((a, b) => a + b);
function leftRightDifference(nums: number[]): number[] {
let [l, r] = [0, nums.reduce((a, b) => a + b, 0)];
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The array destructuring let [l, r] = [...] allocates a temporary array unnecessarily. Prefer separate assignments (e.g., let l = 0; let r = ...;) to avoid the extra allocation and keep the solution tighter.

Suggested change
let [l, r] = [0, nums.reduce((a, b) => a + b, 0)];
let l = 0;
let r = nums.reduce((a, b) => a + b, 0);

Copilot uses AI. Check for mistakes.
right += nums[i];
int* leftRightDifference(int* nums, int numsSize, int* returnSize) {
*returnSize = numsSize;
int* ans = (int*) malloc(sizeof(int) * numsSize);
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

In C, casting the result of malloc is unnecessary and can mask missing #include <stdlib.h> in some toolchains. Prefer int* ans = malloc(sizeof(*ans) * numsSize); (or at least omit the cast) to follow common C best practices.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +40
for i in (0..n).rev() {
for j in (0..n).rev() {
if s[i] == s[j] {
if i == n - 1 || j == n - 1 {
if lcp[i][j] != 1 {
return "".to_string();
}
} else if lcp[i][j] != lcp[i + 1][j + 1] + 1 {
return "".to_string();
}
} else if lcp[i][j] > 0 {
return "".to_string();
}
}
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

This validation iterates over the full n x n matrix even though the conditions are symmetric in i/j (i.e., lcp[i][j] mirrors lcp[j][i]). You can cut the work roughly in half by iterating only one triangle (e.g., j from 0..=i) while keeping the same checks, which helps if n is large.

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

c Issues or Pull requests relate to .c code 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