-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_leetcode_problem.py
More file actions
32 lines (23 loc) · 944 Bytes
/
create_leetcode_problem.py
File metadata and controls
32 lines (23 loc) · 944 Bytes
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
"""
Helper that creates file given LeetCode problem title
Example:
>>> python create_leetcode_problem.py py "1. My Problem"
1_my_problem.py created!
>>> python create_leetcode_problem.py java "1. My Problem"
1_my_problem.java created!
"""
import sys
if __name__ == '__main__':
file_extension = sys.argv[1]
problem_title = sys.argv[2]
if file_extension not in ['py', 'java', 'cpp']:
raise Exception('Invalid file extension')
problem_id, problem_name = problem_title.split('. ')
problem_name = problem_name.lower().replace(' ', '_')
file_name = f'{problem_id}_{problem_name}.{file_extension}'
with open(f'leetcode/{file_name}', 'w'):
pass
print(f'{file_name} created!')
problem_link = problem_name.replace('_', '-')
print('README problem link:')
print(f'[{problem_title}](./leetcode/{file_name}) ([description](https://leetcode.com/problems/{problem_link}/))')