Conversation
There was a problem hiding this comment.
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_differencenaming 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.
| impl Solution { | ||
| pub fn find_the_string(lcp: Vec<Vec<i32>>) -> String { | ||
| let n = lcp.len(); |
There was a problem hiding this comment.
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.
| l += x; | ||
| } | ||
| return ans; | ||
| } |
There was a problem hiding this comment.
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).
| } | |
| }; |
| 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)]; |
There was a problem hiding this comment.
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.
| let [l, r] = [0, nums.reduce((a, b) => a + b, 0)]; | |
| let l = 0; | |
| let r = nums.reduce((a, b) => a + b, 0); |
| right += nums[i]; | ||
| int* leftRightDifference(int* nums, int numsSize, int* returnSize) { | ||
| *returnSize = numsSize; | ||
| int* ans = (int*) malloc(sizeof(int) * numsSize); |
There was a problem hiding this comment.
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.
| 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(); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
No description provided.