@@ -53,6 +53,11 @@ const (
5353 cacheDuration = time .Hour * 24
5454)
5555
56+ // Parse ...
57+ // param: 222
58+ // param: https://leetcode-cn.com/problems/k-th-symbol-in-grammar
59+ // param: https://leetcode-cn.com/problems/k-th-symbol-in-grammar/solution/
60+ // param: leetcode-cn.com/problems/k-th-symbol-in-grammar
5661func Parse (param string ) string {
5762 if match , err := regexp .MatchString (`\d+` , param ); err == nil && match {
5863 stat , err := ProblemID2name (param )
@@ -61,20 +66,34 @@ func Parse(param string) string {
6166 }
6267 }
6368
69+ return ParseFromURL (param )
70+ }
71+
72+ // ParseFromURL
73+ // param: https://leetcode-cn.com/problems/k-th-symbol-in-grammar
74+ // param: https://leetcode-cn.com/problems/k-th-symbol-in-grammar/solution/
75+ // param: leetcode-cn.com/problems/k-th-symbol-in-grammar
76+ func ParseFromURL (param string ) string {
6477 if strings .HasPrefix (param , "http" ) ||
6578 strings .HasPrefix (param , "leetcode-cn.com" ) {
6679
6780 re := regexp .MustCompile (`leetcode-cn\.com/problems/(.*)` )
6881
6982 result := re .FindStringSubmatch (param )
7083 if len (result ) == 2 {
71- return strings .Trim (result [1 ], "/" )
84+ result := strings .Trim (result [1 ], "/" )
85+ ss := strings .Split (result , "/" )
86+ if len (ss ) == 2 {
87+ result = ss [0 ]
88+ }
89+ return result
7290 }
7391 }
7492
7593 return ""
7694}
7795
96+ // ProblemID2name return problem info
7897func ProblemID2name (id string ) (stats QuestionStats , err error ) {
7998 allProblemsDir := path .Join ("questions" , "all_problems.json" )
8099 // 文件是否存在 / 结果是否过期
0 commit comments