Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# LeetCodeNote
# LeetCodeNote

## Solved Problems

<!-- The list of solved problems will be generated here -->
43 changes: 43 additions & 0 deletions generate_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import re

def parse_solution_files():
solution_files = []
for root, _, files in os.walk("."):
for file in files:
if file.endswith(".cs"):
solution_files.append(os.path.join(root, file))
return solution_files

def extract_problem_info(file_path):
with open(file_path, "r") as file:
content = file.read()
match = re.search(r"https://leetcode.com/problems/([a-zA-Z0-9\-]+)/", content)
if match:
url = match.group(0)
title = match.group(1).replace("-", " ").title()
return title, url
return None, None

def generate_solved_problems_list(solution_files):
solved_problems = []
for file_path in solution_files:
title, url = extract_problem_info(file_path)
if title and url:
solved_problems.append(f"- [{title}]({url})")
return solved_problems

def update_readme(solved_problems):
with open("README.md", "r") as file:
readme_content = file.read()

solved_problems_section = "## Solved Problems\n\n" + "\n".join(solved_problems) + "\n"
updated_readme_content = re.sub(r"## Solved Problems\n\n.*", solved_problems_section, readme_content, flags=re.DOTALL)

with open("README.md", "w") as file:
file.write(updated_readme_content)

if __name__ == "__main__":
solution_files = parse_solution_files()
solved_problems = generate_solved_problems_list(solution_files)
update_readme(solved_problems)
Loading