diff --git a/.generate/TEMPLATE.j2 b/.generate/TEMPLATE.j2 index 53bac0d..5cc8e2b 100644 --- a/.generate/TEMPLATE.j2 +++ b/.generate/TEMPLATE.j2 @@ -2,9 +2,10 @@ This repository contains my solutions to various problems on [LeetCode](https://leetcode.com/). -Below is the full table containing all the problems I have solved so far. The table is [automatically generated](./.generate/main.py). - -{{ table }} +Below is the full table containing all the problems I have solved so far. The table is [automatically generated](./.generate/main.py)automatically generated. +| # | Title | Solution | Difficulty | +|---| ----- | -------- | ---------- | +{{ rows }} Generated on {{ date }} diff --git a/.generate/main.py b/.generate/main.py index 173729b..8ca05f8 100755 --- a/.generate/main.py +++ b/.generate/main.py @@ -52,10 +52,7 @@ def main(): cache_path=ROOT_DIRECTORY / "questions.json", cache_time=60 * 60 * 24 ) - table = [ - "| # | Title | Solution | Difficulty |", - "|-|-|-|-|", - ] + table = [] children = list(SOLUTIONS_DIRECTORY.glob("*/")) logger.debug(f"Found {len(children)} children.") @@ -90,24 +87,24 @@ def main(): ) columns = [ - f"[{question.id}]({question.url})", + question.id, f"[{question.title}]({question.url})", solutions, question.difficulty, ] row = "| " + " | ".join(map(str, columns)) + " |" + table.append((question.id, row)) - table.append(row) - - table = "\n".join(table) + table.sort(key=lambda row: row[0]) + rows = "\n".join(row[1] for row in table) with TEMPLATE_PATH.open("r") as template_file: template = Template(template_file.read()) with (ROOT_DIRECTORY / "README.md").open("w") as readme_file: readme_file.write( - template.render(date=datetime.now().strftime("%Y-%m-%d"), table=table) + template.render(date=datetime.now().strftime("%Y-%m-%d"), rows=rows) ) diff --git a/.generate/questions.py b/.generate/questions.py index c71f210..69495d4 100644 --- a/.generate/questions.py +++ b/.generate/questions.py @@ -79,7 +79,7 @@ class QuestionDatabase(object): self.questions = [ Question(**question) for question in raw_cache["questions"] ] - logger.info(f"Loaded {len(self.questions)} questions from cache.") + logger.info(f"Loaded {len(self.questions):,} questions from cache.") else: logger.info(f"Cache file {cache_path} does not exist.") diff --git a/README.md b/README.md index ffc1271..45e6589 100644 --- a/README.md +++ b/README.md @@ -2,27 +2,26 @@ This repository contains my solutions to various problems on [LeetCode](https://leetcode.com/). -Below is the full table containing all the problems I have solved so far. The table is [automatically generated](./.generate/main.py). - +Below is the full table containing all the problems I have solved so far. The table is [automatically generated](./.generate/main.py)automatically generated. | # | Title | Solution | Difficulty | -|-|-|-|-| -| [8](https://leetcode.com/problems/string-to-integer-atoi) | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [Java](/solutions/string-to-integer-atoi/Solution.java) | Medium | -| [5](https://leetcode.com/problems/longest-palindromic-substring) | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [Java](/solutions/longest-palindromic-substring/Solution.java) | Medium | -| [1636](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [Java](/solutions/sort-array-by-increasing-frequency/Solution.java) | Easy | -| [1](https://leetcode.com/problems/two-sum) | [Two Sum](https://leetcode.com/problems/two-sum) | [Java](/solutions/two-sum/Solution.java) | Easy | -| [1608](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [Java](/solutions/special-array-with-x-elements-greater-than-or-equal-x/Solution.java) | Easy | -| [4](https://leetcode.com/problems/median-of-two-sorted-arrays) | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays) | [Rust (Two Pointers)](/solutions/median-of-two-sorted-arrays/src/bin/two-pointers.rs) | Hard | -| [2](https://leetcode.com/problems/add-two-numbers) | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [Java](/solutions/add-two-numbers/Solution.java) | Medium | -| [1048](https://leetcode.com/problems/longest-string-chain) | [Longest String Chain](https://leetcode.com/problems/longest-string-chain) | [Java](/solutions/longest-string-chain/Solution.java) | Medium | -| [7](https://leetcode.com/problems/reverse-integer) | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](/solutions/reverse-integer/Solution.java) | Medium | -| [6](https://leetcode.com/problems/zigzag-conversion) | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [Java](/solutions/zigzag-conversion/Solution.java) | Medium | -| [9](https://leetcode.com/problems/palindrome-number) | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [Java](/solutions/palindrome-number/Solution.java) | Easy | -| [238](https://leetcode.com/problems/product-of-array-except-self) | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [Rust](/solutions/product-of-array-except-self/src/main.rs) | Medium | -| [13](https://leetcode.com/problems/roman-to-integer) | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](/solutions/roman-to-integer/Solution.java) | Easy | -| [3](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [Java](/solutions/longest-substring-without-repeating-characters/Solution.java) | Medium | -| [387](https://leetcode.com/problems/first-unique-character-in-a-string) | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string) | [Java](/solutions/first-unique-character-in-a-string/Solution.java), [Java (HashMap)](/solutions/first-unique-character-in-a-string/Solution_HashMap.java) | Easy | -| [1487](https://leetcode.com/problems/making-file-names-unique) | [Making File Names Unique](https://leetcode.com/problems/making-file-names-unique) | [Java](/solutions/making-file-names-unique/Solution.java), [Java (RegEx)](/solutions/making-file-names-unique/Solution_regex.java), [Python](/solutions/making-file-names-unique/Solution.py) | Medium | -| [451](https://leetcode.com/problems/sort-characters-by-frequency) | [Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency) | [Java](/solutions/sort-characters-by-frequency/Solution.java) | Medium | +|---| ----- | -------- | ---------- | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [Java](/solutions/two-sum/Solution.java) | Easy | +| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [Java](/solutions/add-two-numbers/Solution.java) | Medium | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [Java](/solutions/longest-substring-without-repeating-characters/Solution.java) | Medium | +| 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays) | [Rust (Two Pointers)](/solutions/median-of-two-sorted-arrays/src/bin/two-pointers.rs) | Hard | +| 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [Java](/solutions/longest-palindromic-substring/Solution.java) | Medium | +| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [Java](/solutions/zigzag-conversion/Solution.java) | Medium | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](/solutions/reverse-integer/Solution.java) | Medium | +| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [Java](/solutions/string-to-integer-atoi/Solution.java) | Medium | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [Java](/solutions/palindrome-number/Solution.java) | Easy | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](/solutions/roman-to-integer/Solution.java) | Easy | +| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [Rust](/solutions/product-of-array-except-self/src/main.rs) | Medium | +| 387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string) | [Java](/solutions/first-unique-character-in-a-string/Solution.java), [Java (HashMap)](/solutions/first-unique-character-in-a-string/Solution_HashMap.java) | Easy | +| 451 | [Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency) | [Java](/solutions/sort-characters-by-frequency/Solution.java) | Medium | +| 1048 | [Longest String Chain](https://leetcode.com/problems/longest-string-chain) | [Java](/solutions/longest-string-chain/Solution.java) | Medium | +| 1487 | [Making File Names Unique](https://leetcode.com/problems/making-file-names-unique) | [Java](/solutions/making-file-names-unique/Solution.java), [Java (RegEx)](/solutions/making-file-names-unique/Solution_regex.java), [Python](/solutions/making-file-names-unique/Solution.py) | Medium | +| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [Java](/solutions/special-array-with-x-elements-greater-than-or-equal-x/Solution.java) | Easy | +| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [Java](/solutions/sort-array-by-increasing-frequency/Solution.java) | Easy | Generated on 2023-10-08