This repository automatically collects my accepted LeetCode submissions and organizes them into a clean, browsable structure. There's no manual copy-pasting - a scheduled GitHub Action fetches my latest solutions straight from LeetCode's API and commits them for me.
Every solved problem gets its own folder containing the solution file and a README with the problem's difficulty, topics, and a direct link.
flowchart LR
A([⏰ Daily Cron<br/>Midnight UTC]) --> B[🤖 GitHub Action]
B --> C[🐍 sync_leetcode.py]
C --> D{{🌐 LeetCode<br/>GraphQL API}}
D --> E[📥 Fetch accepted<br/>submissions + code]
E --> F[📂 Write to<br/>problem folders]
F --> G[✅ Commit & Push<br/>new solutions]
- Scheduled trigger - a GitHub Action runs every day at midnight UTC (also triggerable manually).
- Fetch - a Python script queries LeetCode's GraphQL API for recently accepted submissions.
- Organize - each solution is written to its own numbered folder with a generated README.
- Commit - only new or changed solutions are committed, keeping the history clean.
LeetCode/
├── .github/workflows/
│ └── sync.yml # ⚙️ Daily sync workflow
├── scripts/
│ └── sync_leetcode.py # 🐍 The sync engine
├── requirements.txt # 📦 Python dependencies
│
├── 0001-two-sum/
│ ├── 0001-two-sum.py # 💡 Solution
│ └── README.md # 📄 Problem details
├── 0002-add-two-numbers/
│ └── ...
└── ...
Want to fork this and sync your own solutions? Here's how.
1. Add your LeetCode credentials as repository secrets
Go to Settings → Secrets and variables → Actions and add:
| Secret Name | Where to find it |
|---|---|
LEETCODE_SESSION |
Browser cookie LEETCODE_SESSION on leetcode.com |
LEETCODE_CSRF_TOKEN |
Browser cookie csrftoken on leetcode.com |
2. How to grab your cookies
- Log in to leetcode.com
- Open DevTools (
F12) → Application → Cookies →https://leetcode.com - Copy
LEETCODE_SESSIONandcsrftoken - Paste them into the matching repository secrets
3. Run it
Head to the Actions tab → Sync LeetCode Solutions → Run workflow. After the first run, it syncs automatically every day. 🎉
⚠️ Heads up: LeetCode session cookies expire every couple of weeks. When sync stops working, just refresh theLEETCODE_SESSIONsecret with a fresh cookie value.