This tool automatically syncs your LeetCode solutions to GitHub, organizing them by difficulty level and maintaining detailed documentation for each problem.
- GitHub account
- LeetCode account
- Python 3.10 or higher
- Fork or clone this repository
- Go to your repository's Settings > Secrets and variables > Actions
- Add the following secrets:
GH_PAT: Your GitHub Personal Access Token (with repo access)LEETCODE_SESSION: Your LeetCode session cookie
- Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
- Click "Generate new token (classic)"
- Select the following scopes:
repo(Full control of private repositories)
- Copy the generated token and save it as
GH_PATin your repository secrets
- Login to LeetCode in your browser
- Open Developer Tools (F12)
- Go to Application > Cookies > leetcode.com
- Find and copy the value of
LEETCODE_SESSION - Save it as
LEETCODE_SESSIONin your repository secrets
- The sync runs automatically at midnight on the 1st of every month
- Solutions are organized in folders by difficulty:
easy/ medium/ hard/
You can trigger a manual sync:
- Go to your repository's Actions tab
- Select "Sync LeetCode Solutions" workflow
- Click "Run workflow"
Each problem gets its own folder with:
difficulty/
└── xxxx-problem-name/
├── README.md # Problem details & stats
└── solution.{ext} # Your solution file
- Python (.py)
- JavaScript (.js)
- Java (.java)
- C++ (.cpp)
- And other LeetCode-supported languages
- Syncs only accepted solutions
- Updates existing solutions if improved
- Maintains problem descriptions and statistics
- Organizes by difficulty level
- Supports multiple programming languages
-
Workflow Failed
- Check if your secrets are correctly set
- Verify your LeetCode session is still valid
- Check GitHub Actions logs for specific errors
-
Solutions Not Syncing
- Ensure solutions are "Accepted" on LeetCode
- Check if LeetCode session is expired
- Verify repository permissions
-
Missing Problems
- Only accepted solutions are synced
- Check last sync date in Actions tab
- Try running manual sync
If you encounter issues:
- Check the Actions tab for error logs
- Verify your secrets are correctly set
- Ensure your LeetCode session is valid
- Solve problems on LeetCode first
- Ensure solutions are accepted before sync
- Use clear, well-documented code
- Commit any manual changes before sync
- The sync only picks up "Accepted" solutions
- Each problem's README includes:
- Problem description
- Difficulty level
- Your solution's stats
- Submission date
- LeetCode problem link