@@ -176,6 +176,133 @@ SOLUTIONS = {
176176}
177177```
178178
179+ ### A.7 Solution Comment Format
180+
181+ Solutions SHOULD include structured comments to explain the algorithm, approach, and key insights. This section defines the standard comment format.
182+
183+ #### A.7.1 File-Level Docstring
184+
185+ Every solution file SHOULD start with a docstring describing the problem:
186+
187+ ``` python
188+ """
189+ Problem: Two Sum
190+ Link: https://leetcode.com/problems/two-sum/
191+
192+ Given an array of integers nums and an integer target, return indices
193+ of the two numbers such that they add up to target.
194+
195+ Constraints:
196+ - 2 <= nums.length <= 10^4
197+ - -10^9 <= nums[i] <= 10^9
198+ - -10^9 <= target <= 10^9
199+ - Only one valid answer exists.
200+ """
201+ ```
202+
203+ | Field | Required | Description |
204+ | -------| ----------| -------------|
205+ | ` Problem ` | ✅ | Problem title |
206+ | ` Link ` | ✅ | LeetCode URL |
207+ | Description | Recommended | Brief problem statement |
208+ | ` Constraints ` | Recommended | Key constraints affecting algorithm choice |
209+
210+ #### A.7.2 Solution Block Comments
211+
212+ Each solution class SHOULD be preceded by a block comment explaining the approach.
213+
214+ ** No blank line** between the comment block and the class definition:
215+
216+ ``` python
217+ # ============================================================================
218+ # Solution 1: Sliding Window (Optimized with Jump)
219+ # Time: O(n), Space: O(min(n, σ))
220+ # - Each character visited at most twice
221+ # - Uses last-seen-index array for O(1) duplicate detection
222+ # - Direct position jumping instead of incremental contraction
223+ # ============================================================================
224+ class SolutionSlidingWindow : # ← 緊接著,無空行
225+ ...
226+ ```
227+
228+ ** Format:**
229+
230+ ```
231+ # ============================================
232+ # Solution {N}: {Approach Name}
233+ # Time: O(?), Space: O(?)
234+ # - {Key insight or implementation detail}
235+ # - {Additional notes}
236+ # ============================================
237+ class ClassName: # ← No blank line before class/function
238+ ```
239+
240+ | Component | Required | Description |
241+ | -----------| ----------| -------------|
242+ | Solution number & name | ✅ | e.g., ` Solution 1: Sliding Window ` |
243+ | Time/Space complexity | ✅ | e.g., ` Time: O(n), Space: O(n) ` |
244+ | Bullet points | Recommended | Key insights, implementation details |
245+ | ** No blank line** | ✅ | Comment block directly followed by class/function |
246+
247+ ** More examples:**
248+
249+ ``` python
250+ # ============================================
251+ # Solution 1: Single Pass
252+ # Time: O(max(m,n)), Space: O(max(m,n))
253+ # - Single pass through both lists
254+ # - Result list has at most max(m,n) + 1 nodes
255+ # ============================================
256+ class Solution :
257+ ...
258+ ```
259+
260+ ``` python
261+ # ============================================================================
262+ # Solution 2: Using Dictionary (More Flexible for Unicode)
263+ # Time: O(n), Space: O(min(n, σ))
264+ # - Same sliding window approach with dictionary instead of array
265+ # - More flexible for Unicode strings but slightly slower
266+ # ============================================================================
267+ class SolutionDict :
268+ ...
269+ ```
270+
271+ ``` python
272+ # ============================================================================
273+ # Solution 3: Using Set (Standard While-Loop Pattern)
274+ # Time: O(n), Space: O(min(n, σ))
275+ # - Uses set to track current window characters
276+ # - Demonstrates standard while-loop contraction pattern
277+ # ============================================================================
278+ class SolutionSet :
279+ ...
280+ ```
281+
282+ #### A.7.3 JUDGE_FUNC Comments (Optional)
283+
284+ When defining a ` JUDGE_FUNC ` , you MAY include a block comment explaining its purpose and complexity.
285+
286+ Same rule: ** no blank line** between comment and function:
287+
288+ ``` python
289+ # ============================================
290+ # JUDGE_FUNC - Required for generator support
291+ # ============================================
292+ # Uses brute force O(m+n) merge to compute the correct answer,
293+ # then compares with the solution output.
294+ # ============================================
295+ def judge (actual , expected , input_data : str ) -> bool : # ← 無空行
296+ ...
297+
298+ JUDGE_FUNC = judge
299+ ```
300+
301+ This is optional but recommended when:
302+ - The judge uses a different algorithm than the solution
303+ - The judge has notable complexity characteristics
304+ - Generator support requires custom validation
305+
179306---
180307
181308## B. SOLUTIONS Metadata Schema
@@ -629,6 +756,12 @@ When adding or modifying a solution, verify:
629756"""
630757Problem: {Problem Title}
631758Link: https://leetcode.com/problems/{slug}/
759+
760+ {Brief problem description}
761+
762+ Constraints:
763+ - {constraint 1}
764+ - {constraint 2}
632765"""
633766from typing import List
634767from _runner import get_solver
@@ -652,9 +785,12 @@ SOLUTIONS = {
652785}
653786
654787# ============================================
655- # Solution class(es)
788+ # Solution 1: {Approach Name}
789+ # Time: O(?), Space: O(?)
790+ # - {Key insight or implementation detail}
791+ # - {Additional notes}
656792# ============================================
657- class Solution :
793+ class Solution : # ← No blank line after comment block
658794 def methodName (self , ...):
659795 ...
660796
0 commit comments