/sf-domain-leetcode:lc-addfrom sf-domain-leetcode
File a LeetCode solution into this repo the way the existing ones are filed — find the problem's real slug, write the Python file in the house layout (problem docstring, V0 with an IDEA block and a time/space line), smoke-test it against the examples, and insert the README row. Use when asked to "add LC <number>", to file a problem just solved in a weekly contest, to turn a pasted draft into a committed solution, or to wire an existing solution file into README. Triggers - "add LC 4038 to Hash_table", "/lc-add 239 Sliding_Window", "add this solution and update the README", "file yesterday's contest Q1".
Ships in sf-domain-leetcode. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Turn an LC number (plus, usually, a draft the user already wrote) into a committed-quality solution file and its README row, in the shape the other ~826 Python files already use.
Invocation: /lc-add <LC number> <pattern dir> — e.g. /lc-add 4038 Hash_table.
A reference or draft solution pasted under the command is used as V0; with no draft, the
draft is usually already in the contest scratch file (step 1).
Missing arguments are inferred, not asked about: the pattern dir from the technique the solution actually uses, the language from where the draft came from (default Python). Ask only if the number itself is missing or the dir is genuinely ambiguous.
countSpecialIntegers and its problem is Count Integers Appearing in a
Single Block. A slug guessed from a method name lands on the wrong file name and a
dead README link.V0. Replacing it with a cleverer one teaches nothing and hides the bug
they wanted found.For a contest problem it is leetcode_python/lc_weekly/weekly_<n>/ws.txt — it records the
LC number, the problem URL, the user's idea notes and their draft (often with the bug they
hit, then a (fixed) version below it):
grep -rn "LC <number>" leetcode_python/lc_weekly/*/ws.txt
sed -n '/# LC <number>/,/^# LC /p' leetcode_python/lc_weekly/weekly_<n>/ws.txt
Two things to read out of it:
count-integers-appearing-in-a-single-block.If the user pasted a URL, that is the source of truth and this step is done. A pasted statement without a URL is not enough: look up the official problem page for the URL and slug, and if that fails, ask the user for the URL instead of guessing the slug.
ls leetcode_python/<Pattern_Dir>/
git log --oneline -12 --name-only # the last few files added, in any dir
Open one recent file from the target dir and match it. The layout below is the current house shape, but the dir wins if it has drifted.
leetcode_python/<Pattern_Dir>/<slug>.py"""
<number>. <Exact Problem Title>
<Difficulty>
<the statement, as prose — wrapped, not one long line>
Example 1:
Input: nums = [1,1,2,2,3]
Output: 3
Explanation:
<why>
Constraints:
1 <= nums.length <= 10^5
"""
# V0
# IDEA : <ONE LINE — THE TECHNIQUE, IN CAPS LIKE ITS NEIGHBOURS>
#
# <2-6 indented lines saying WHY the trick is correct — the invariant, not a
# restatement of the loop. A worked mini-example earns its place here:>
#
# e.g. nums = [1,2,1] -> idx of 1 = [0,2] -> 2 - 0 + 1 = 3 != 2 -> NOT special
#
# time = O(n), space = O(n)
from collections import defaultdict
class Solution(object):
def <lcMethodName>(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
# edge
if not nums:
return 0
...
Rules that are not negotiable:
# V0 is the canonical solution. # IDEA : ... header, indented why, then
# time = O(...), space = O(...) as the last comment line before the code.:type: / :rtype: docstring stays on the method — these files are pasted
back into LC.# NOTE !!! marks the one line a reader would get wrong. Use it once, not five times.class Solution(object) — it is what the whole tree uses.One canonical solution per problem. A second one is justified only by a different
complexity, a distinct trick, or a different language idiom — not a different spelling of
the same loop. When justified it is # V0-1 (a variation on V0) or # V1 (a genuinely
different approach), each with its own IDEA and time = line, and the class is named
Solution2 / Solution3 so the file still imports.
The file name has dashes, so it is not importable — load it by path and run the docstring's
examples plus the edges the problem's constraints allow (empty, single element, all-same —
only when valid inputs). Match the method's real signature: LC 239 takes (nums, k), and
an empty nums is not a valid input there. The call below is for a one-argument method:
python3 -c "
import importlib.util
spec = importlib.util.spec_from_file_location('m', 'leetcode_python/<Dir>/<slug>.py')
m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
s = m.Solution()
print([s.<method>(x) for x in ([1,1,2,2,3], [1,2,1], [5], [])])"
Every variant gets the same call, and they must agree. If an example from the problem statement disagrees, the solution is wrong — say so rather than adjusting the example.
Find the pattern's table and insert in ascending LC-number order (a 4-digit contest problem goes at the end of that table):
grep -n "leetcode_python/<Pattern_Dir>" README.md | tail -5
| <num> | [<Title>](<leetcode url>) | [Python](./leetcode_python/<Dir>/<slug>.py) | _O(t)_ | _O(s)_ | <Difficulty> | **<pattern>**, <tags>, LC weekly | AGAIN(1) |
git show <sha> -- README.md on a previous
update <NNN> py commit shows the exact column shape.Java link into the same cell only if that file exists under
leetcode_java/ — check, do not assume the pair.hashmap, prefix sum, span == cnt trick), then LC weekly for a contest problem,
then company tags in backticks if known.AGAIN(1) for a first pass. Never downgrade a status the user has set.Close with the file, the README line number, the test results, and every inference:
difficulty from contest position, examples written from the rule because ws.txt kept only
the statement, a Java link deliberately omitted.
data/progress.txt — the practice log is the user's own record and gets its own
commitlc-add 4038 Hash_table, with the user's draft pasted:
| Step | What it produced |
|---|---|
| 1 | weekly_517/ws.txt → slug count-integers-appearing-in-a-single-block, first of 4038/4039/4040/4041 → Easy |
| 2 | read count-special-triplets.py from the same dir |
| 3 | wrote the file; IDEA explains why last - first + 1 == count is the contiguity test |
| 4 | added V0-1 (keep only first/last/cnt) — justified: O(distinct) space, not O(n) cells |
| 5 | [1,1,2,2,3]→3, [1,2,1]→1, [5]→1, [1,2,1,3,3,2]→1, []→0, both variants agreeing |
| 6 | README row inserted after LC 4007, the last row of the hash-table table |
| 7 | flagged: difficulty inferred from contest position, examples written from the rule |
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub yennanliu/skill-factory-1 --plugin sf-domain-leetcode2 skills in this plugin