This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This repository supports a local configuration file for personalized settings:
CLAUDE.local.md- User-specific configuration (gitignored, won't affect other users)- Create this file to customize behavior without modifying shared config
Example CLAUDE.local.md:
## Daily Problem Strategy
- If `solution.py` exists → use Go (`solution.go`)
- Otherwise → use primary language from `.env`Claude Code automatically reads CLAUDE.local.md if it exists.
This is a LeetCode solutions repository with multi-language support. Each problem has a dedicated folder with solutions in Python, Go, Java, C++, TypeScript, and Rust.
The main workflow is solving the daily LeetCode problem. In this mode:
- Act as an algorithm mentor - provide guidance, suggestions, and optimization strategies
- Discuss algorithmic improvements, trade-offs between approaches
- Share language-specific idioms and optimizations (e.g., Python's
bisect, Go'sslices, C++'sstd::lower_bound) - Review solutions for correctness, efficiency, and code quality
- Primary language: Read from
.envfile'sLANGUAGESfield (e.g.,LANGUAGES="python3",LANGUAGES="go,java"). First language is the primary one. - Use modern syntax: Use the latest language features (Python 3.12+, Go 1.21+, C++23, etc.) when applicable
- This mode typically runs at least once daily
When iterating on project infrastructure, build systems, or architecture:
- Act as a software architect/engineer
- Changes should remain local only - not pushed to remote
- Only the repository owner modifies architecture; other users just consume the project
- Focus on: build tooling, test infrastructure, new language support, CI/CD
Note: The .claude/ memory files (memory/) are for local AI context only and should NOT be pushed to remote - they help AI understand project context but aren't part of the codebase.
problems/problems_N/- Solution folder for LeetCode problem Nsolution.py- Python solutiontestcase.py- Test cases (Python class format)testcase- Test cases (JSON format:[inputs_str, outputs])solution.go,Solution.java,Solution.cpp,solution.rs,solution.ts- Other language implementationslink.json- Link to another problem with identical solution (see Problem Linking section)
python/- Base classes (Solution,Testcase) and CLI toolsalgorithm_templates/- Algorithm templates (binary search, sliding window, DP, graph algorithms, etc.)
Create a .env file at repository root with:
PYTHONPATH=.
PROBLEM_FOLDER="problems"
AUTO_LINK_SIMILAR="false" # Set to "true" to enable auto-linking similar problemsWithout PYTHONPATH=., Python imports will fail with ModuleNotFoundError: No module named 'python'.
pip install -r python/requirements.txt# Single problem test (reads "daily" field from daily-{folder}.json)
PYTHONPATH=. python python/test.py
# Multiple problems test (reads "plans" field from daily-{folder}.json)
PYTHONPATH=. python python/tests.pyThe JSON config file is daily-{folder}.json at repository root, where {folder} matches PROBLEM_FOLDER in .env (defaults to problems → daily-problems.json).
Example config:
{
"daily": "2751",
"plans": ["3833", "problems", "3834", "problems"]
}The plans array alternates between problem IDs and folder names.
PYTHONPATH=. python python/scripts/leetcode.pyInteractive menu with options: Get Problem, Submit, Change Test, Contest, Clean, Favorites.
All scripts require PYTHONPATH=. and read config from .env / daily-{folder}.json.
| Script | Purpose | Key Args |
|---|---|---|
get_problem.py |
Fetch problem by ID/slug | -id PROBLEM_ID, -slug SLUG, -f (force overwrite) |
daily_auto.py |
Auto-generate daily problem + study plans | No args |
submit.py |
Submit solution to LeetCode | LANG -id=ID (LANG required: py/go/java/cpp/ts/rs) |
daily_submission.py |
Fetch accepted submissions from LeetCode | No args |
tools.py |
Backfill ratings, random/remain problems | rating, lucky, remain subcommands |
leetcode_cookie_updater.py |
Auto-update Cookie from browser | --repo REPO, --env PATH |
spider.py |
Extract holidays/problems from HTML | holiday, problems subcommands |
ranking_crawler.py |
Crawl LeetCode ranking stats | No args |
batch_link_lcr.py |
Batch link LCR problems to main site | No args |
import solution
from typing import *
class Solution(solution.Solution):
def solve(self, test_input=None):
return self.methodName(*test_input)
def methodName(self, ...) -> ReturnType:
# Implementation
passfrom collections import namedtuple
import testcase
case = namedtuple("Testcase", ["Input", "Output"])
class Testcase(testcase.Testcase):
def __init__(self):
self.testcases = []
self.testcases.append(case(Input=[...], Output=[...]))
def get_testcases(self):
return self.testcasesAll languages read from daily-{folder}.json config file except Rust (see notes below).
| Language | Single Problem | Multiple Problems |
|---|---|---|
| Python | PYTHONPATH=. python python/test.py |
PYTHONPATH=. python python/tests.py |
| Go | go test -tags=goexperiment.jsonv2 golang/solution_test.go golang/test_basic.go -test.timeout 3s |
go test -tags=goexperiment.jsonv2 golang/problems_test.go golang/test_basic.go -test.timeout 10s |
| Java | mvn test -Dtest="qubhjava.test.TestMain" |
mvn test -Dtest="qubhjava.test.ProblemsTest" |
| TypeScript | npm test --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022 typescript/test.ts |
npm test --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022 typescript/problems.test.ts |
| C++ | bazel test //:daily_test --cxxopt=-std=c++23 --cxxopt=-O2 --test_output=all |
bazel test $(bazel query 'filter("plan_*", kind(cc_test, //...))') --cxxopt=-std=c++23 --test_output=all |
| Rust | cargo test --test solution_test |
cargo test --test solutions_test |
Go:
- Requires
-tags=goexperiment.jsonv2forencoding/json/v2(Go 1.25+) - Run
PYTHONPATH=. python golang/go_setup.pyto generatesolution_test.goandproblems_test.gofromdaily-{folder}.json - Must use specific file paths (not package path) to avoid compiling all test files:
# Single problem - only compiles solution_test.go go test -tags=goexperiment.jsonv2 golang/solution_test.go golang/test_basic.go -test.timeout 3s # Multiple problems - only compiles problems_test.go go test -tags=goexperiment.jsonv2 golang/problems_test.go golang/test_basic.go -test.timeout 10s
Rust:
- Test configuration requires dynamic setup (like Java):
- Run
PYTHONPATH=. python rust/cargo_setup.pyto generate minimalCargo.toml - Run
cargo test --test solution_test - Restore with
cp Cargo.toml.full Cargo.tomlwhen done
- Run
- The script reads
daily-{folder}.jsonand only compiles configured problems
TypeScript:
- Requires
npm installfirst to getjest
C++:
- Optional AddressSanitizer for memory debugging: add
--cxxopt=-fsanitize=address --linkopt=-fsanitize=addressto bazel commands
Environment Dependencies:
- Java: Maven (
mvn) - TypeScript: Node.js + npm
- C++: Bazel
- Rust: Cargo
- Base classes
SolutionandTestcaseinpython/solution.pyandpython/testcase.pydefine abstractsolve()andget_testcases()methods - Test runner dynamically imports
solution.pyandtestcase.pyfrom problem folders usingimportlib - Language writers in
python/lc_libs/handle multi-language solution generation and submission
When two problems have identical or nearly identical solutions (e.g., same problem with different constraints), use the link feature to avoid duplicate code:
# Create a link from problem 3741 to problem 3740
PYTHONPATH=. python python/scripts/link_problem.py -t 3741 -s 3740 -r "Same problem, different constraints (n <= 10^5 vs n <= 100)"
# Create link and delete existing solution files (including Cargo.toml)
PYTHONPATH=. python python/scripts/link_problem.py -t 3741 -s 3740 -r "reason" -dThis creates a link.json file in the target problem folder:
{
"link_to": "3740",
"link_folder": "problems",
"reason": "Same problem, different constraints (n <= 10^5 vs n <= 100)"
}The test framework automatically resolves links and uses the linked solution.
Auto-linking is controlled by the AUTO_LINK_SIMILAR environment variable:
| Setting | Behavior |
|---|---|
AUTO_LINK_SIMILAR=false (default) |
No auto-linking |
AUTO_LINK_SIMILAR=true |
Auto-detect and link similar problems |
When enabled, the system compares:
- Problem descriptions (normalized, ignoring constraints)
- Method signatures (method name, parameters, return type)
- Title similarity (ignoring version numbers like I, II, III)
If a similar problem is found (≥70% similarity), only link.json is created instead of solution files.
For GitHub Actions, set AUTO_LINK_SIMILAR secret to true in repository settings.