Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
russhustle committed Feb 22, 2025
1 parent bf269af commit f11340c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.formatOnSave": true,
"prettier.tabWidth": 2,
"prettier.tabWidth": 4,
"makefile.configureOnOpen": false,
"prettier.embeddedLanguageFormatting": "auto",
"prettier.bracketSameLine": false,
Expand Down
6 changes: 3 additions & 3 deletions docs/md/0001_two_sum.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## 1. Two Sum

- [LeetCode](https://leetcode.com/problems/two-sum/) | [LeetCode CH](https://leetcode.cn/problems/two-sum/) (Easy)
- [LeetCode](https://leetcode.com/problems/two-sum/) | [LeetCode CH](https://leetcode.cn/problems/two-sum/) (Easy)

- Return the indices of the two numbers such that they add up to a specific target.

| Approach | Time Complexity | Space Complexity |
| -------- | --------------- | ---------------- |
| Hashmap | O(n) | O(n) |
| :------: | :-------------: | :--------------: |
| Hashmap | O(n) | O(n) |
72 changes: 35 additions & 37 deletions utils/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,64 @@

import pandas as pd

from config import code, load_config_yaml
from config import code, load_config_yaml, sql_code


class ProblemList:
def __init__(self, file: str):
self.src = "src"
self.docs = "docs"
self.data = load_config_yaml(os.path.join(self.src, "config", file))
self.dir = os.path.join(self.docs, self.data.dir)
self.df = pd.read_parquet(os.path.join("utils", "questions.parquet"))
self.cfg = load_config_yaml(os.path.join(self.src, "config", file))
self.dir = os.path.join(self.docs, self.cfg.dir)
os.makedirs(self.dir, exist_ok=True)

self.pattern = re.compile(r"^\d{4}_")

# mkdocs
self.tab = 4 * " "
self.mkdocs_yaml = f"{self.tab}- {self.data.name}:\n"
self.mkdocs_yaml += (
f"{self.tab}{self.tab}- Home: {self.data.dir}/index.md\n"
)

# index
self.index_md_path = os.path.join(self.docs, self.data.dir, "index.md")
self.index_md_path = os.path.join(self.docs, self.cfg.dir, "index.md")
if not os.path.exists(self.index_md_path):
with open(self.index_md_path, "w") as outfile:
outfile.write(f"# {self.data.name}\n")
outfile.write(f"# {self.cfg.name}\n")

for topic, problems in self.data.topics.items():
self.generate_topic_markdown(topic, problems)
self.pattern = re.compile(r"^\d{4}_")

print(self.mkdocs_yaml)
# mkdocs
self.mkdocs_yaml = f"- {self.cfg.name}:\n"
self.mkdocs_yaml += f" - Home: {self.cfg.dir}/index.md\n"

def generate_topic_markdown(self, topic: str, problems, comments=True):
files = [
file
for problem in problems
for file in os.listdir(self.src)
if file.endswith(".py")
and self.pattern.match(file)
and int(file.split("_")[0]) == problem
]
for topic, problems in self.cfg.topics.items():
self.generate_topic_markdown(topic, problems)

def generate_topic_markdown(self, topic: str, problems, comments=True):
title = f"# {topic}\n\n"
md_name = topic.lower().replace(" ", "_") + ".md"
md_path = os.path.join(self.docs, self.data.dir, md_name)
md_path = os.path.join(self.docs, self.cfg.dir, md_name)

self.mkdocs_yaml += (
f"{self.tab}{self.tab}- {topic}: {self.data.dir}/{md_name}\n"
)
self.mkdocs_yaml += f" - {topic}: {self.cfg.dir}/{md_name}\n"

with open(md_path, "w") as outfile:
outfile.write(f"---\ncomments: {comments}\n---\n\n")
outfile.write(title)

for file in files:
filename = file.split(".")[0]
md_file_path = os.path.join("docs", "md", filename + ".md")
with open(md_file_path, "r") as infile:
data = infile.read()

outfile.write(data + code(filename) + "\n")
for qid in problems:
content = self.problem_markdown(qid)
outfile.write(content)

def problem_markdown(self, qid: int):
row = self.df[self.df.QID == qid]
name = row["titleSlug"].values[0]
basename = str(qid).zfill(4) + "_" + name
filename = os.path.join(self.dir, basename + ".md")

if os.path.exists(filename):
with open(filename, "r") as infile:
content = infile.read()
content += code(basename) + "\n"
else:
content = row["markdown"].values[0]
with open(filename, "w") as f:
f.write(content + "\n")

return content


if __name__ == "__main__":
Expand Down

0 comments on commit f11340c

Please sign in to comment.