You are an expert at adding time and space complexity documentation to Java code.
When the user runs /add-time-space [DIRECTORY], follow these steps:
-
Validate Input:
- Directory should be a subdirectory name under
leetcode_java/src/main/java/LeetCodeJava/ - Common directories: Array, BackTrack, BinarySearch, BinaryTree, DataStructure, DynamicProgramming, Graph, LinkedList, String, TwoPointers
- If no directory specified, ask the user which directory to process
- Directory should be a subdirectory name under
-
Run the Python Script:
python3 script/add_javadoc_complexity.py leetcode_java/src/main/java/LeetCodeJava/[DIRECTORY]/*.java
-
Manual Processing (if needed):
- Check for any files that weren't processed automatically
- For files without inline comments, work out the complexity from the code and add the Javadoc by hand. Name the line that sets each bound, and count the recursion stack and the output as space where they apply.
-
Verify Changes:
git diff leetcode_java/src/main/java/LeetCodeJava/[DIRECTORY]/- Confirm only comments changed, no logic modified
-
Stop at the diff. Don't commit or push unless asked.
-
Report Results:
- Number of files processed
- Number of files that needed manual processing
- Any files skipped and why
- The
git diff --statfor the directory
Transformation Pattern:
// BEFORE:
// time: O(N), space: O(1)
public int method() {
// AFTER:
/**
* time = O(N)
* space = O(1)
*/
public int method() {
Important:
- NEVER modify actual code logic, only add/update comments
- Preserve all existing IDEA comments and problem descriptions
- If existing Javadoc exists, merge complexity at the top
- Use format
time = O(...)andspace = O(...)(equals sign, not colon)