-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_leetcode_problem.py
More file actions
46 lines (32 loc) · 1.32 KB
/
Copy pathcreate_leetcode_problem.py
File metadata and controls
46 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import sys
TARGET_ROOT = sys.argv[1] or "Blind 75"
TEMPLATE_PATH = "algorithm_template.md"
def load_template():
with open(TEMPLATE_PATH, "r") as f:
return f.read()
def create_problem_directory(name, link):
dir_path = os.path.join(TARGET_ROOT, name)
os.makedirs(dir_path, exist_ok=True)
# Create code.py
open(os.path.join(dir_path, "code.py"), "w").close()
# Create README.md with replaced link and problem name
template = load_template().replace("[Leetcode #]", f"[Leetcode {name}]")
template = template.replace("[Link]: https://leetcode.com/problems/", f"[Link]: {link}")
with open(os.path.join(dir_path, "README.md"), "w") as f:
f.write(template)
print(f"\033[34mSuccessfully created a new Leetcode problem:\033[3m \'{dir_path}\' \033[0m")
def main():
problem_name, link = "", ""
if len(sys.argv) == 4:
problem_name = sys.argv[2]
link = sys.argv[3]
elif len(sys.argv) == 3:
problem_name = sys.argv[1]
link = sys.argv[2]
else:
problem_name = input("Enter problem name (e.g., '412. Fizzbuzz'): ").strip()
link = input("Enter Leetcode link (or press Enter for default): ").strip() or "https://leetcode.com/problems/"
create_problem_directory(problem_name, link)
if __name__ == "__main__":
main()