Awesome-omni-skill better-leetcode
Optimize and refactor LeetCode solutions to be more elegant, readable, and idiomatic. Use when the user provides code from a LeetCode problem and wants to improve code quality, simplify logic, enhance variable naming, or make the solution more concise and maintainable. Also use when the user asks to "optimize", "refactor", "improve", or "clean up" LeetCode code.
git clone https://github.com/diegosouzapw/awesome-omni-skill
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data-ai/better-leetcode" ~/.claude/skills/diegosouzapw-awesome-omni-skill-better-leetcode && rm -rf "$T"
skills/data-ai/better-leetcode/SKILL.mdBetter LeetCode
Refactor LeetCode solutions to follow clean code principles: clear logic, intuitive variable names, minimal comments, and idiomatic patterns.
Core Principles
- Clear over clever: Prefer readable solutions that are easy to understand at first glance
- Minimal comments: Code should be self-documenting through good naming and clear structure
- Idiomatic patterns: Use well-known algorithms and data structures with their standard implementations
- Concise variable names: Use short but meaningful names that follow common conventions
Refactoring Guidelines
Variable Naming
Use standard, memorable variable names for common patterns:
- Pointers:
,slow
,fast
,left
,right
,i
,jk - Lists/Arrays:
,nums
,arr
,resans - Trees:
,root
,node
,leftright - Graphs:
,graph
,node
,visitedadj - Strings:
,s
,t
,wordpattern - Counters:
,count
,cntfreq - Results:
,res
,ansresult
Code Structure
Do:
- Keep functions focused and simple
- Use early returns to reduce nesting
- Prefer while loops for unclear iteration counts
- Use for loops with range for known iterations
- Initialize variables close to usage
Avoid:
- Excessive comments explaining obvious logic
- Overly complex one-liners that sacrifice readability
- Unnecessary temporary variables
- Deep nesting (>3 levels)
Common Patterns
Two Pointers:
slow = fast = head while fast and fast.next: fast = fast.next.next slow = slow.next
Sliding Window:
left = 0 for right in range(len(s)): # expand window while condition: # shrink window left += 1
Binary Search:
left, right = 0, len(nums) - 1 while left <= right: mid = (left + right) // 2 if nums[mid] == target: return mid elif nums[mid] < target: left = mid + 1 else: right = mid - 1
DFS (Tree):
def dfs(node): if not node: return # process node dfs(node.left) dfs(node.right)
BFS:
from collections import deque queue = deque([start]) while queue: node = queue.popleft() # process node if condition: queue.append(next_node)
Optimization Process
When refactoring code:
- Analyze: Identify the algorithm/pattern being used
- Simplify: Remove unnecessary complexity and redundancy
- Rename: Apply standard variable naming conventions
- Structure: Organize code for maximum readability
- Verify: Ensure logic correctness is maintained
Focus on readability and maintainability over micro-optimizations unless performance is explicitly required.