This document describes the development workflow for contributing to the LeetCode solutions repository, including local quality gates, automated CI/CD pipelines, and the pull request lifecycle. Contributors use this workflow to add new solutions, update existing code, and maintain documentation quality across 10+ programming languages.
For information about the repository structure and problem organization, see Problem Organization. For details about multi-language code formatting standards, see Code Formatting System.
The repository enforces code quality through pre-commit hooks that run automatically before commits are created. These local checks catch formatting and style issues before code reaches CI/CD pipelines.
The repository uses Husky to manage Git hooks. When developers run npm install, Husky automatically installs pre-commit hooks configured in package.json2-4
The prepare script executes during npm install, setting up Git hooks that intercept commit operations.
The lint-staged tool runs formatters only on files that are staged for commit, optimizing performance by avoiding full repository scans. Configuration is defined in package.json15-19:
| File Pattern | Formatter | Purpose |
|---|---|---|
*.{js,ts,php,sql,md} | prettier --write | Format JavaScript, TypeScript, PHP, SQL, Markdown |
*.py | black -S | Format Python (skip string normalization) |
*.rs | rustfmt | Format Rust |
The -S flag for Black prevents string quote normalization, preserving the repository's existing string style conventions.
Commit messages must follow Conventional Commits specification, enforced by @commitlint/config-conventional package.json6-7 Valid commit types include:
feat: - New problem solutionsfix: - Bug fixes in existing solutionsdocs: - Documentation updatesstyle: - Code formatting (no logic changes)refactor: - Code restructuringtest: - Test additions or modificationschore: - Maintenance tasksExample valid commit:
feat: add solution for problem 125 in Go
Added two-pointer solution with O(n) time complexity
Code style is unified through Prettier with specific settings in .prettierrc1-22:
| Setting | Value | Impact |
|---|---|---|
tabWidth | 4 | Consistent indentation across languages |
singleQuote | true | Use single quotes in JavaScript/TypeScript |
printWidth | 100 | Maximum line length |
phpVersion | "8.1" | PHP syntax targeting |
sqlKeywordCase | "upper" | SQL keywords in uppercase |
Special plugins handle domain-specific formatting:
prettier-plugin-sql-cst for SQL files@prettier/plugin-php for PHP filesSources: package.json1-20 .prettierrc1-22
GitHub Actions orchestrates all automation, from code formatting to deployment. Workflows are triggered by pushes, pull requests, schedules, or manual dispatches.
Concurrency Control: All workflows use group: ${{github.workflow}} - ${{github.ref}} with cancel-in-progress: true to prevent redundant runs when new commits are pushed.
Sources: .github/workflows/deploy.yml17-19 .github/workflows/prettier.yml7-9 .github/workflows/black-lint.yml23-25
The main deployment workflow builds bilingual documentation sites and publishes to GitHub Pages. It runs on pushes to main that modify solution directories.
Key Implementation Details:
main branch is merged with configuration from docs branch using rsync .github/workflows/deploy.yml37-40main.py runs before MkDocs to generate dynamic content .github/workflows/deploy.yml82docs branch for author attribution .github/workflows/deploy.yml89-112site.tar.gz for artifact upload, reducing transfer time .github/workflows/deploy.yml114-124Environment Variables:
MKDOCS_API_KEYS - Secret API keys for MkDocs plugins .github/workflows/deploy.yml77-78Sources: .github/workflows/deploy.yml1-154
Three separate workflows handle formatting for different language ecosystems:
Runs on pull_request_target to format files from external contributors. Uses pull_request_target instead of pull_request to access repository secrets safely .github/workflows/prettier.yml4-5
Process:
git diff --name-only filtered by \.js$|\.ts$|\.php$|\.sql$|\.md$ .github/workflows/prettier.yml32npx prettier --write on changed files only .github/workflows/prettier.yml35"style: format code and docs with prettier" .github/workflows/prettier.yml39-44Identity: Commits are made by idoocs bot (doocs-bot@outlook.com) .github/workflows/prettier.yml43-44
Validates Python code formatting on pushes and PRs. Does not auto-fix; contributors must run Black locally .github/workflows/black-lint.yml1-36
Trigger Paths:
solution/**lcs/**, lcp/**, lcof2/**, lcof/**, lcci/**basic/**Configuration: Uses jpetrucciani/black-check@24.2.0 action with -S flag to skip string normalization .github/workflows/black-lint.yml33-35
Similar to Black workflow but for C, C++, and Java files. Validates formatting without auto-fixing .github/workflows/clang-format-lint.yml1-36
Sources: .github/workflows/prettier.yml1-45 .github/workflows/black-lint.yml1-36 .github/workflows/clang-format-lint.yml1-36
Updates the star growth chart every 12 hours using cron schedule "0 0/12 * * *" .github/workflows/starcharts.yml5
Process:
MaoLongLong/actions-starcharts@main action .github/workflows/starcharts.yml14images/starcharts.svg .github/workflows/starcharts.yml17"chore: auto update starcharts" .github/workflows/starcharts.yml18STARS_CHANGE to track star count deltas .github/workflows/starcharts.yml19Output: The SVG is embedded in README via <img src="./images/starcharts.svg"> README.md201
Optimizes images on push, PR, weekly schedule, and manual dispatch. Uses Calibre's image-actions tool .github/workflows/compress.yml28-55
Behavior:
'00 23 * * 0' (Sunday at 23:00 UTC) .github/workflows/compress.yml20Tool: calibreapp/image-actions@main optimizes JPEG, PNG, WebP formats .github/workflows/compress.yml40
Sources: .github/workflows/starcharts.yml1-20 .github/workflows/compress.yml1-55
The PR lifecycle includes automated checks, team member detection, and maintainer review before merge.
Contributors follow the standard GitHub fork workflow described in README.md182-191:
Branch Naming Convention: While not enforced, descriptive names like feat/problem-125-go or docs/update-contributing help identify PR purpose.
Sources: README.md182-191
When a PR is opened, GitHub Actions run multiple validation workflows:
Prettier Auto-fix Behavior: Unlike Black/Clang-format workflows that only validate, Prettier workflow automatically commits formatting fixes using stefanzweifel/git-auto-commit-action@v5 .github/workflows/prettier.yml39-44
Team Member Detection: The pr-add-label.yml workflow checks if PR author belongs to doocs/leetcode-algorithm team and adds appropriate labels .github/workflows/pr-add-label.yml19-25:
Team members' PRs are marked for priority review.
Sources: .github/workflows/prettier.yml1-45 .github/workflows/black-lint.yml1-36 .github/workflows/pr-add-label.yml1-26
After automated checks pass:
main branchleetcode.doocs.org .github/workflows/deploy.yml6-15Deployment Trigger: Only pushes to main affecting solution paths trigger deployment:
Sources: .github/workflows/deploy.yml6-15 README.md182-191
The repository welcomes contributions of new solutions, improvements to existing solutions, and documentation updates. The process is documented in README.md182-195:
https://github.com/doocs/leetcode and click "Fork"git clone https://github.com/YOUR_USERNAME/leetcodegit checkout -b feat/add-solution-125 (use descriptive name)npm install && git add . && git commit -m "test" (triggers pre-commit hooks)git push origin feat/add-solution-125doocs/leetcode:mainSolutions are organized by problem series and number ranges. For standard LeetCode problems:
Path Pattern: solution/[RANGE]/[PROBLEM_ID].[Problem Title]/
Example: Problem 125 "Valid Palindrome"
solution/0100-0199/0125.Valid Palindrome/
├── README.md # Chinese description and solutions
├── README_EN.md # English description and solutions
├── Solution.py # Python implementation
├── Solution.java # Java implementation
├── Solution.cpp # C++ implementation
├── Solution.go # Go implementation
├── Solution.ts # TypeScript implementation
├── Solution.rs # Rust implementation
└── ... # Other languages
Range Directories:
0000-0099/ - Problems 0-990100-0199/ - Problems 100-1993700-3799/ - Problems 3700-3799Other Series:
lcof/ - 剑指 Offer (2nd Edition)lcof2/ - 剑指 Offer (Special Edition)lcci/ - Cracking the Coding Interview (6th Edition)lcp/ - LeetCode Cup contest problemslcs/ - LeetCode Season contest problemsbasic/ - Basic algorithms (sorting, searching)Sources: README.md26-30 solution/0100-0199/0125.Valid Palindrome/README.md1-10
Each solution file should follow language-specific patterns:
Formatting Requirements:
Each problem directory must contain bilingual README files following this template:
README.md (Chinese):
Example: See solution/0100-0199/0125.Valid Palindrome/README.md1-80 for complete template
Required Elements:
comments, difficulty, edit_url, tagsSources: solution/0100-0199/0125.Valid Palindrome/README.md1-224 solution/0100-0199/0125.Valid Palindrome/README_EN.md1-224
The basic/ directory contains tutorial-style explanations of fundamental algorithms. Structure:
basic/
├── README.md # Index (Chinese)
├── README_EN.md # Index (English)
├── sorting/
│ ├── BubbleSort/
│ │ └── README.md # Tutorial with code examples
│ ├── QuickSort/
│ │ └── README.md
│ └── ...
└── searching/
└── BinarySearch/
└── README.md
Tutorial Format: Each algorithm tutorial should include:
Example: basic/sorting/BubbleSort/README.md1-220 demonstrates the standard tutorial format with Python, Java, C++, Go, Rust, JavaScript, and C# implementations.
Sources: basic/README.md1-32 basic/sorting/BubbleSort/README.md1-220 basic/searching/BinarySearch/README.md1-60
All commits must follow Conventional Commits specification enforced by commitlint. Valid format:
<type>(<scope>): <subject>
<body>
<footer>
Common Types:
| Type | Usage | Example |
|---|---|---|
feat | New solution | feat: add solution for problem 125 in Python |
fix | Bug fix | fix: correct time complexity in problem 200 |
docs | Documentation | docs: update README for binary search tutorial |
style | Formatting | style: format code with black |
refactor | Code restructure | refactor: optimize space complexity in problem 1 |
test | Tests | test: add test cases for problem 125 |
chore | Maintenance | chore: update dependencies |
Scope (Optional): Can specify problem number, directory, or component
feat(0125): add Go solutiondocs(basic): add merge sort tutorialAuto-generated Commits: Workflow bots use specific formats:
"style: format code and docs with prettier" - Prettier workflow"chore: auto update starcharts" - Starcharts workflow"chore: auto compress images" - Image compression workflowSources: package.json6-7 .github/workflows/prettier.yml42 .github/workflows/starcharts.yml18
-S flag (skip string normalization)def method(self, nums: List[int]) -> int:class Solution:class Solution {}vector<int>, unordered_map<int, int>gofmt formatting (standard)package main or omit for solution snippetsfunc methodName(param Type) ReturnType {}function methodName(param: Type): ReturnType {}rustfmt (standard)impl Solution {} block&str over String for string parameters when possibleSources: package.json15-19 requirements.txt1-2 .prettierrc1-22
Issue: Commit rejected with formatting errors
Solution:
npm installgit add .git commit -m "your message"Manual Formatting:
Issue: black-lint.yml workflow fails on PR
Cause: Python code not formatted with Black
Solution:
Issue: Prettier workflow runs but doesn't commit fixes
Cause: Workflow only runs on pull_request_target for external contributors
Solution: For maintainers and team members, format locally before pushing:
Issue: Added images but compress workflow didn't run
Cause: Workflow only triggers on specific paths:
Solution: Ensure image files use supported extensions. Manually trigger via Actions tab if needed.
Sources: .github/workflows/compress.yml6-17
Community Support:
YLB0109 with note "leetcode" README.md222Sources: README.md220-227
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.