Skip to content

feat: update solutions to lc problem: No.1406 - #5335

Merged
yanglbme merged 2 commits into
mainfrom
dev
Aug 3, 2026
Merged

feat: update solutions to lc problem: No.1406#5335
yanglbme merged 2 commits into
mainfrom
dev

Conversation

@yanglbme

@yanglbme yanglbme commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Update solutions for lc problem No.1406 (Stone Game III) in Python, Java, C++, Go, and TypeScript, and format all code (black, clang-format, gofmt, prettier)
  • Add new Rust solution and include the Rust tab in README/README_EN
  • Update the Chinese and English solution descriptions to match the new code: enumerate the index j of the last pile taken, with transition dfs(i) = max{ sum(stoneValue[i..j]) - dfs(j + 1) } over i <= j < min(i+3, n)

Test plan

  • Verify black, clang-format, gofmt, prettier, and rustfmt checks all pass
  • Verify README code blocks match the formatted solution files
  • Review the rendered README/README_EN on the docs site

yanglbme and others added 2 commits August 3, 2026 09:40
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings August 3, 2026 01:45
@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@yanglbme
yanglbme merged commit 76564b9 into main Aug 3, 2026
8 checks passed
@yanglbme
yanglbme deleted the dev branch August 3, 2026 01:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The Python and TypeScript solutions use deep recursion with n up to 5*10^4, which is likely to hit recursion/call-stack limits and fail on worst-case inputs.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR updates the multi-language solutions and documentation for LeetCode 1406. Stone Game III in the solution/ collection, aligning the recurrence with “enumerate the last taken pile index j” and adding a new Rust implementation.

Changes:

  • Refactors the memoized transition in Python/Java/C++/Go/TypeScript to iterate j as the last taken index (dfs(i) = max(sum(i..j) - dfs(j+1))).
  • Adds a new Rust solution and adds the Rust tab/code block to README.md and README_EN.md.
  • Updates Chinese/English writeups to match the revised transition and reformats code blocks.
File summaries
File Description
solution/1400-1499/1406.Stone Game III/Solution.py Updates DFS transition loop to enumerate last-taken index j.
solution/1400-1499/1406.Stone Game III/Solution.java Same transition refactor; uses Integer.MIN_VALUE sentinel.
solution/1400-1499/1406.Stone Game III/Solution.cpp Replaces VLA+memset with vector<int> + INT_MIN and updates recursion style.
solution/1400-1499/1406.Stone Game III/Solution.go Updates loop form and memo sentinel.
solution/1400-1499/1406.Stone Game III/Solution.ts Updates loop form and memo sentinel; keeps recursive memoization.
solution/1400-1499/1406.Stone Game III/Solution.rs Adds new Rust memoized solution implementation.
solution/1400-1499/1406.Stone Game III/README.md Updates explanation/formula and refreshes code blocks; adds Rust tab.
solution/1400-1499/1406.Stone Game III/README_EN.md Same as Chinese README updates; adds Rust tab.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 3
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment on lines 3 to 6
@cache
def dfs(i: int) -> int:
if i >= n:
if i >= len(stoneValue):
return 0
let n = stone_value.len();
let mut f = vec![None; n];

fn dfs(i: usize, stone_value: &Vec<i32>, f: &mut Vec<Option<i32>>) -> i32 {
Comment on lines 5 to 8
const dfs = (i: number): number => {
if (i >= n) {
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants