Skip to content

Commit af0d25e

Browse files
committed
feat: add template
1 parent 5366c57 commit af0d25e

File tree

8 files changed

+265
-9
lines changed

8 files changed

+265
-9
lines changed

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"program": "${workspaceFolder}/cmd/leetcode-readme-gen.go",
2020
"cwd": "${workspaceFolder}",
2121
"args": [
22-
"1"
22+
"3223"
2323
],
2424
"env": {},
2525
"dlvFlags": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: 0010.Regular-Expression-Matching
3+
subtitle: "https://leetcode.com/problems/regular-expression-matching/description/"
4+
date: 2025-04-11T20:59:36+08:00
5+
lastmod: 2025-04-11T20:59:36+08:00
6+
draft: false
7+
author: "Kimi.Tsai"
8+
authorLink: "https://kimi0230.github.io/"
9+
description: "Regular-Expression-Matching"
10+
license: ""
11+
images: []
12+
13+
tags: [LeetCode, Go, Hard, String, Dynamic Programming, Recursion]
14+
categories: [LeetCode]
15+
16+
featuredImage: ""
17+
featuredImagePreview: ""
18+
19+
hiddenFromHomePage: false
20+
hiddenFromSearch: false
21+
twemoji: false
22+
lightgallery: true
23+
ruby: true
24+
fraction: true
25+
fontawesome: true
26+
linkToMarkdown: false
27+
rssFullText: false
28+
29+
toc:
30+
enable: true
31+
auto: true
32+
code:
33+
copy: true
34+
maxShownLines: 200
35+
math:
36+
enable: false
37+
mapbox:
38+
share:
39+
enable: true
40+
comment:
41+
enable: true
42+
library:
43+
css:
44+
js:
45+
seo:
46+
images: []
47+
---
48+
49+
# [0010.Regular-Expression-Matching](https://leetcode.com/problems/regular-expression-matching/description/)
50+
51+
## 題目
52+
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
53+
54+
55+
'.' Matches any single character.​​​​
56+
'*' Matches zero or more of the preceding element.
57+
58+
59+
The matching should cover the entire input string (not partial).
60+
61+
 
62+
Example 1:
63+
64+
65+
Input: s = "aa", p = "a"
66+
Output: false
67+
Explanation: "a" does not match the entire string "aa".
68+
69+
70+
Example 2:
71+
72+
73+
Input: s = "aa", p = "a*"
74+
Output: true
75+
Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
76+
77+
78+
Example 3:
79+
80+
81+
Input: s = "ab", p = ".*"
82+
Output: true
83+
Explanation: ".*" means "zero or more (*) of any character (.)".
84+
85+
86+
 
87+
Constraints:
88+
89+
90+
1 <= s.length <= 20
91+
1 <= p.length <= 20
92+
s contains only lowercase English letters.
93+
p contains only lowercase English letters, '.', and '*'.
94+
It is guaranteed for each appearance of the character '*', there will be a previous valid character to match.
95+
96+
## 題目大意
97+
98+
99+
## 解題思路
100+
101+
102+
## 來源
103+
* https://leetcode.com/problems/regular-expression-matching/description/
104+
105+
## 解答
106+
https://github.com/kimi0230/LeetcodeGolang/blob/master/Leetcode/0010.Regular-Expression-Matching/main.go
107+
108+
109+
110+
## Benchmark
111+
112+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func isMatch(s string, p string) bool {
2+
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestExample(t *testing.T) {
8+
// TODO: add test cases
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: 3223.Minimum-Length-of-String-After-Operations
3+
subtitle: "https://leetcode.com/problems/minimum-length-of-string-after-operations/description/"
4+
date: 2025-04-11T20:56:29+08:00
5+
lastmod: 2025-04-11T20:56:29+08:00
6+
draft: false
7+
author: "Kimi.Tsai"
8+
authorLink: "https://kimi0230.github.io/"
9+
description: "Minimum-Length-of-String-After-Operations"
10+
license: ""
11+
images: []
12+
13+
tags: [LeetCode, Go, Medium, Hash Table, String, Counting]
14+
categories: [LeetCode]
15+
16+
featuredImage: ""
17+
featuredImagePreview: ""
18+
19+
hiddenFromHomePage: false
20+
hiddenFromSearch: false
21+
twemoji: false
22+
lightgallery: true
23+
ruby: true
24+
fraction: true
25+
fontawesome: true
26+
linkToMarkdown: false
27+
rssFullText: false
28+
29+
toc:
30+
enable: true
31+
auto: true
32+
code:
33+
copy: true
34+
maxShownLines: 200
35+
math:
36+
enable: false
37+
mapbox:
38+
share:
39+
enable: true
40+
comment:
41+
enable: true
42+
library:
43+
css:
44+
js:
45+
seo:
46+
images: []
47+
---
48+
49+
# [3223.Minimum-Length-of-String-After-Operations](https://leetcode.com/problems/minimum-length-of-string-after-operations/description/)
50+
51+
## 題目
52+
You are given a string s.
53+
54+
You can perform the following process on s any number of times:
55+
56+
57+
Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i].
58+
Delete the closest occurrence of s[i] located to the left of i.
59+
Delete the closest occurrence of s[i] located to the right of i.
60+
61+
62+
Return the minimum length of the final string s that you can achieve.
63+
64+
 
65+
Example 1:
66+
67+
68+
Input: s = "abaacbcbb"
69+
70+
Output: 5
71+
72+
Explanation:
73+
We do the following operations:
74+
75+
76+
Choose index 2, then remove the characters at indices 0 and 3. The resulting string is s = "bacbcbb".
77+
Choose index 3, then remove the characters at indices 0 and 5. The resulting string is s = "acbcb".
78+
79+
80+
81+
Example 2:
82+
83+
84+
Input: s = "aa"
85+
86+
Output: 2
87+
88+
Explanation:
89+
We cannot perform any operations, so we return the length of the original string.
90+
91+
92+
 
93+
Constraints:
94+
95+
96+
1 <= s.length <= 2 * 105
97+
s consists only of lowercase English letters.
98+
99+
## 題目大意
100+
101+
102+
## 解題思路
103+
104+
105+
## 來源
106+
* https://leetcode.com/problems/minimum-length-of-string-after-operations/description/
107+
108+
## 解答
109+
https://github.com/kimi0230/LeetcodeGolang/blob/master/Leetcode/3223.Minimum-Length-of-String-After-Operations/main.go
110+
111+
112+
113+
## Benchmark
114+
115+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func minimumLength(s string) int {
2+
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestExample(t *testing.T) {
8+
// TODO: add test cases
9+
}

cmd/leetcode-readme-gen.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type LeetcodeResponse struct {
1919
Data struct {
2020
Question struct {
2121
QuestionID string `json:"questionId"`
22+
FrontendID string `json:"questionFrontendId"`
2223
Title string `json:"title"`
2324
Content string `json:"content"`
2425
Difficulty string `json:"difficulty"`
@@ -37,13 +38,14 @@ type ProblemListResponse struct {
3738
StatStatusPairs []struct {
3839
Stat struct {
3940
QuestionID int `json:"question_id"`
41+
FrontendID int `json:"frontend_question_id"`
4042
QuestionSlug string `json:"question__title_slug"`
4143
} `json:"stat"`
4244
} `json:"stat_status_pairs"`
4345
}
4446

4547
const readmeTemplate = `---
46-
title: {{.ID}}.{{.Title}}
48+
title: {{.FrontendID}}.{{.Title}}
4749
subtitle: "https://leetcode.com/problems/{{.Slug}}/description/"
4850
date: {{.Now}}
4951
lastmod: {{.Now}}
@@ -90,7 +92,7 @@ seo:
9092
images: []
9193
---
9294
93-
# [{{.ID}}.{{.Title}}](https://leetcode.com/problems/{{.Slug}}/description/)
95+
# [{{.FrontendID}}.{{.Title}}](https://leetcode.com/problems/{{.Slug}}/description/)
9496
9597
## 題目
9698
{{.Problem}}
@@ -105,7 +107,7 @@ seo:
105107
* https://leetcode.com/problems/{{.Slug}}/description/
106108
107109
## 解答
108-
https://github.com/kimi0230/LeetcodeGolang/blob/master/Leetcode/{{.ID}}.{{.Title}}/main.go
110+
https://github.com/kimi0230/LeetcodeGolang/blob/master/Leetcode/{{.FrontendID}}.{{.Title}}/main.go
109111
110112
111113
@@ -116,6 +118,7 @@ https://github.com/kimi0230/LeetcodeGolang/blob/master/Leetcode/{{.ID}}.{{.Title
116118

117119
type ReadmeData struct {
118120
ID string
121+
FrontendID string
119122
Title string
120123
Slug string
121124
Difficulty string
@@ -145,7 +148,7 @@ func fetchSlugFromID(id int) (string, error) {
145148
}
146149

147150
for _, p := range problems.StatStatusPairs {
148-
if p.Stat.QuestionID == id {
151+
if p.Stat.FrontendID == id {
149152
return p.Stat.QuestionSlug, nil
150153
}
151154
}
@@ -156,6 +159,7 @@ func fetchLeetcode(slug string) (*ReadmeData, error) {
156159
query := `query questionTitleSlug($titleSlug: String!) {
157160
question(titleSlug: $titleSlug) {
158161
questionId
162+
questionFrontendId
159163
title
160164
content
161165
difficulty
@@ -203,6 +207,7 @@ func fetchLeetcode(slug string) (*ReadmeData, error) {
203207

204208
return &ReadmeData{
205209
ID: q.QuestionID,
210+
FrontendID: fmt.Sprintf("%04s", q.FrontendID),
206211
Title: strings.ReplaceAll(q.Title, " ", "-"),
207212
Slug: slug,
208213
Difficulty: q.Difficulty,
@@ -232,7 +237,7 @@ func stripHTML(input string) string {
232237
}
233238

234239
func writeREADME(data *ReadmeData) error {
235-
dir := fmt.Sprintf("Leetcode/%s.%s", data.ID, data.Title)
240+
dir := fmt.Sprintf("Leetcode/%s.%s", data.FrontendID, data.Title)
236241
os.MkdirAll(dir, 0755)
237242
f, err := os.Create(filepath.Join(dir, "README.md"))
238243
if err != nil {
@@ -247,7 +252,7 @@ func writeREADME(data *ReadmeData) error {
247252
}
248253

249254
func writeMainGo(data *ReadmeData) error {
250-
dir := fmt.Sprintf("Leetcode/%s.%s", data.ID, data.Title)
255+
dir := fmt.Sprintf("Leetcode/%s.%s", data.FrontendID, data.Title)
251256
f, err := os.Create(filepath.Join(dir, "main.go"))
252257
if err != nil {
253258
return err
@@ -258,7 +263,7 @@ func writeMainGo(data *ReadmeData) error {
258263
}
259264

260265
func writeMainTest(data *ReadmeData) error {
261-
dir := fmt.Sprintf("Leetcode/%s.%s", data.ID, data.Title)
266+
dir := fmt.Sprintf("Leetcode/%s.%s", data.FrontendID, data.Title)
262267
f, err := os.Create(filepath.Join(dir, "main_test.go"))
263268
if err != nil {
264269
return err
@@ -308,5 +313,5 @@ func main() {
308313
if err := writeMainTest(data); err != nil {
309314
panic(err)
310315
}
311-
fmt.Printf("README, main.go, and main_test.go generated for %s (%s)\n", data.Title, data.ID)
316+
fmt.Printf("README, main.go, and main_test.go generated for %s (%s)\n", data.Title, data.FrontendID)
312317
}

0 commit comments

Comments
 (0)