Skip to content

Commit a4d024f

Browse files
authored
Merge pull request #3 from ewdlop/generate-readme
Generate the problems I solved on readme
2 parents d30e6c1 + d444d57 commit a4d024f

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# LeetCodeNote
1+
# LeetCodeNote
2+
3+
## Solved Problems
4+
5+
<!-- The list of solved problems will be generated here -->

generate_readme.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import re
3+
4+
def parse_solution_files():
5+
solution_files = []
6+
for root, _, files in os.walk("."):
7+
for file in files:
8+
if file.endswith(".cs"):
9+
solution_files.append(os.path.join(root, file))
10+
return solution_files
11+
12+
def extract_problem_info(file_path):
13+
with open(file_path, "r") as file:
14+
content = file.read()
15+
match = re.search(r"https://leetcode.com/problems/([a-zA-Z0-9\-]+)/", content)
16+
if match:
17+
url = match.group(0)
18+
title = match.group(1).replace("-", " ").title()
19+
return title, url
20+
return None, None
21+
22+
def generate_solved_problems_list(solution_files):
23+
solved_problems = []
24+
for file_path in solution_files:
25+
title, url = extract_problem_info(file_path)
26+
if title and url:
27+
solved_problems.append(f"- [{title}]({url})")
28+
return solved_problems
29+
30+
def update_readme(solved_problems):
31+
with open("README.md", "r") as file:
32+
readme_content = file.read()
33+
34+
solved_problems_section = "## Solved Problems\n\n" + "\n".join(solved_problems) + "\n"
35+
updated_readme_content = re.sub(r"## Solved Problems\n\n.*", solved_problems_section, readme_content, flags=re.DOTALL)
36+
37+
with open("README.md", "w") as file:
38+
file.write(updated_readme_content)
39+
40+
if __name__ == "__main__":
41+
solution_files = parse_solution_files()
42+
solved_problems = generate_solved_problems_list(solution_files)
43+
update_readme(solved_problems)

0 commit comments

Comments
 (0)