Skip to content

Commit 3f1b19e

Browse files
committed
Add solution for "Valid Parentheses" and update README; add GitHub Actions workflow for README updates
1 parent 6f9f85b commit 3f1b19e

File tree

5 files changed

+108
-6
lines changed

5 files changed

+108
-6
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Update README
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
update-readme:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.10'
21+
22+
- name: Install dependencies
23+
run: pip install requests
24+
25+
- name: Run update script
26+
run: python automata.py
27+
28+
- name: Commit and push changes
29+
run: |
30+
git config --global user.name "GitHub Action Bot"
31+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
32+
git add README.md
33+
git diff --staged --quiet || git commit -m "Auto-update README.md"
34+
git push

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
venv

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
| # | Title | Solution | Type | Difficulty |
66
|---| ----- | -------- | ---------- | ---------- |
7-
|0217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/description/) | [Python](./array_hashing/0217-contains-duplicate.py)|Array & Hashing| Easy |
8-
|0242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/description/) | [Python](./array_hashing/0242-valid-anagram.py)|Array & Hashing| Easy |
9-
|0001|[Two Sum](https://leetcode.com/problems/two-sum/description/) | [Python](./array_hashing/0001-two-sum.py)|Array & Hashing| Easy |
10-
|0049|[Group Anagrams](https://leetcode.com/problems/group-anagrams/description/) | [Python](./array_hashing/0049-group-anagrams.py)|Array & Hashing| Medium |
11-
|0125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/) | [Python](./two_pointers/0125-valid-palindrome.py)|Two Pointers| Easy |
12-
|0347|[Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/description/) | [Python](./array_hashing/0347-top-k-frequent-elements.py)|Array & Hashing| Medium |
7+
|0001|[Two Sum](https://leetcode.com/problems/two-sum/description/)|[Python](./array_hashing/0001-two-sum.py)|Array Hashing| Easy |
8+
|0020|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/description/)|[Python](./stack/0020-valid-parentheses.py)|Stack| Easy |
9+
|0049|[Group Anagrams](https://leetcode.com/problems/group-anagrams/description/)|[Python](./array_hashing/0049-group-anagrams.py)|Array Hashing| Medium |
10+
|0125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/)|[Python](./two_pointers/0125-valid-palindrome.py)|Two Pointers| Easy |
11+
|0217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/description/)|[Python](./array_hashing/0217-contains-duplicate.py)|Array Hashing| Easy |
12+
|0242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/description/)|[Python](./array_hashing/0242-valid-anagram.py)|Array Hashing| Easy |
13+
|0347|[Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/description/)|[Python](./array_hashing/0347-top-k-frequent-elements.py)|Array Hashing| Medium |

automata.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import re
3+
import requests
4+
5+
def extract_problem_info(file_path):
6+
match = re.match(r"(\d+)-([a-z0-9-]+)\.py", os.path.basename(file_path))
7+
if match:
8+
problem_number, slug = match.groups()
9+
return int(problem_number), slug, f"[{slug.replace('-', ' ').title()}](https://leetcode.com/problems/{slug}/description/)"
10+
return None, None, None
11+
12+
def get_problem_difficulty(slug):
13+
url = "https://leetcode.com/graphql"
14+
query = """
15+
query getQuestionDifficulty($titleSlug: String!) {
16+
question(titleSlug: $titleSlug) {
17+
difficulty
18+
}
19+
}
20+
"""
21+
response = requests.post(url, json={"query": query, "variables": {"titleSlug": slug}})
22+
try:
23+
data = response.json()
24+
return data["data"]["question"]["difficulty"]
25+
except (KeyError, TypeError):
26+
return "Unknown"
27+
28+
def build_readme():
29+
topics = [d for d in os.listdir('.') if os.path.isdir(d)]
30+
problem_entries = []
31+
32+
for topic in topics:
33+
for file in os.listdir(topic):
34+
if file.endswith(".py"):
35+
problem_number, slug, problem_title = extract_problem_info(file)
36+
if problem_number:
37+
difficulty = get_problem_difficulty(slug)
38+
problem_entries.append((problem_number, problem_title, f"[Python](./{topic}/{file})", topic.replace('_', ' ').title(), difficulty))
39+
40+
problem_entries.sort()
41+
42+
table_header = "| # | Title | Solution | Type | Difficulty |\n|---| ----- | -------- | ---------- | ---------- |"
43+
table_rows = []
44+
45+
for number, title, solution, topic, difficulty in problem_entries:
46+
table_rows.append(f"|{number:04d}|{title}|{solution}|{topic}| {difficulty} |")
47+
48+
table_content = "\n".join([table_header] + table_rows)
49+
readme_content = f"""# Coding Everyday Until I Get A Job
50+
51+
## LeetCode Solutions
52+
53+
{table_content}
54+
"""
55+
56+
with open("README.md", "w", encoding="utf-8") as f:
57+
f.write(readme_content)
58+
59+
if __name__ == "__main__":
60+
build_readme()
61+
print("README.md has been updated!")

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2025.1.31
2+
charset-normalizer==3.4.1
3+
idna==3.10
4+
requests==2.32.3
5+
urllib3==2.3.0

0 commit comments

Comments
 (0)