53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
import os
|
|
import sys
|
|
|
|
def create_package_structure(problem_name, method_signature):
|
|
"""Creates the package structure for a LeetCode problem"""
|
|
|
|
# Convert problem name to package format (lowercase with underscores)
|
|
package_name = problem_name.lower().replace(' ', '_')
|
|
|
|
# Base package path
|
|
base_path = "dsa/src/main/java/com/hithomelabs/dsa/array"
|
|
package_path = f"{base_path}/{package_name}"
|
|
|
|
# Create package directory
|
|
os.makedirs(package_path, exist_ok=True)
|
|
|
|
# Create Solution.java
|
|
solution_content = f"""package com.hithomelabs.dsa.array.{package_name};
|
|
|
|
public class Solution implements Solvable {{
|
|
{method_signature} {{
|
|
// TODO: Implement solution
|
|
throw new UnsupportedOperationException("Not implemented yet");
|
|
}}
|
|
}}
|
|
"""
|
|
|
|
# Create Solvable.java
|
|
solvable_content = f"""package com.hithomelabs.dsa.array.{package_name};
|
|
|
|
interface Solvable {{
|
|
{method_signature};
|
|
}}
|
|
"""
|
|
|
|
# Write files
|
|
with open(f"{package_path}/Solution.java", "w") as f:
|
|
f.write(solution_content)
|
|
|
|
with open(f"{package_path}/Solvable.java", "w") as f:
|
|
f.write(solvable_content)
|
|
|
|
def main():
|
|
if len(sys.argv) != 3:
|
|
print("Usage: python generate_leetcode_structure.py \"Problem Name\" \"method_signature\"")
|
|
sys.exit(1)
|
|
|
|
problem_name = sys.argv[1]
|
|
method_signature = sys.argv[2]
|
|
create_package_structure(problem_name, method_signature)
|
|
|
|
if __name__ == "__main__":
|
|
main() |