-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
feat: add TypeScript solution for lc No.1977 #4952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 adds a TypeScript solution for LeetCode problem 1977 ("Number of Ways to Separate Numbers") and refactors the Java and C++ solutions to move constant declarations inside the method scope.
Key Changes:
- Added a new TypeScript implementation of the dynamic programming algorithm
- Refactored Java and C++ solutions to use local constant declarations instead of class-level constants
- Updated documentation files to include the TypeScript solution
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Solution.ts | New TypeScript solution implementing the dynamic programming algorithm with LCP preprocessing |
| Solution.java | Refactored to move mod constant from class-level to method scope |
| Solution.cpp | Refactored to move mod constant from class-level to method scope |
| README_EN.md | Added TypeScript code example to English documentation |
| README.md | Added TypeScript code example to Chinese documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| } | ||
|
|
||
| function cmp(i: number, j: number, k: number): boolean { |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name 'cmp' is ambiguous. Consider renaming it to something more descriptive like 'isLexicographicallyGreaterOrEqual' or 'compareSubstrings' to clarify its purpose of comparing substrings lexicographically.
| let v: number = 0; | ||
| if (num[i - j] !== '0') { | ||
| if (i - j - j >= 0 && cmp(i - j, i - j - j, j)) { | ||
| v = dp[i - j][j]; | ||
| } else { | ||
| v = dp[i - j][Math.min(j - 1, i - j)]; | ||
| } | ||
| } | ||
| dp[i][j] = (dp[i][j - 1] + v) % mod; |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name 'v' is not descriptive. Consider renaming it to something more meaningful like 'validWays' or 'count' to indicate it represents the number of valid ways at this position.
| let v: number = 0; | |
| if (num[i - j] !== '0') { | |
| if (i - j - j >= 0 && cmp(i - j, i - j - j, j)) { | |
| v = dp[i - j][j]; | |
| } else { | |
| v = dp[i - j][Math.min(j - 1, i - j)]; | |
| } | |
| } | |
| dp[i][j] = (dp[i][j - 1] + v) % mod; | |
| let validWays: number = 0; | |
| if (num[i - j] !== '0') { | |
| if (i - j - j >= 0 && cmp(i - j, i - j - j, j)) { | |
| validWays = dp[i - j][j]; | |
| } else { | |
| validWays = dp[i - j][Math.min(j - 1, i - j)]; | |
| } | |
| } | |
| dp[i][j] = (dp[i][j - 1] + validWays) % mod; |
No description provided.