From d01f4f4e39d2296669b2997990b25d2f592fd6bd Mon Sep 17 00:00:00 2001 From: songyzh Date: Thu, 13 Feb 2020 20:39:40 +0800 Subject: [PATCH 1/3] add problem link and discuss link --- src/main.rs | 15 ++++++++++++++- template.rs | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ae16b34d..6fecf106 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,6 +188,17 @@ fn parse_extra_use(code: &str) -> String { extra_use_line } +fn parse_problem_link(problem: &Problem) -> String { + format!("https://leetcode.com/problems/{}/", problem.title_slug) +} + +fn parse_discuss_link(problem: &Problem) -> String { + format!( + "https://leetcode.com/problems/{}/discuss/?currentPage=1&orderBy=most_votes&query=", + problem.title_slug + ) +} + fn insert_return_in_code(return_type: &str, code: &str) -> String { let re = Regex::new(r"\{[ \n]+}").unwrap(); match return_type { @@ -326,7 +337,9 @@ fn deal_problem(problem: &Problem, code: &CodeDefinition, write_mod_file: bool) &insert_return_in_code(&problem.return_type, &code.default_code), ) .replace("__PROBLEM_ID__", &format!("{}", problem.question_id)) - .replace("__EXTRA_USE__", &parse_extra_use(&code.default_code)); + .replace("__EXTRA_USE__", &parse_extra_use(&code.default_code)) + .replace("__PROBLEM_LINK__", &parse_problem_link(problem)) + .replace("__DISCUSS_LINK__", &parse_discuss_link(problem)); let mut file = fs::OpenOptions::new() .write(true) diff --git a/template.rs b/template.rs index 06c5c06d..11411f01 100644 --- a/template.rs +++ b/template.rs @@ -5,6 +5,9 @@ */ pub struct Solution {}__EXTRA_USE__ +// problem: __PROBLEM_LINK__ +// discuss: __DISCUSS_LINK__ + // submission codes start here __PROBLEM_DEFAULT_CODE__ From 089fb47748c12e8264e503b8d590fbd1ac6dc571 Mon Sep 17 00:00:00 2001 From: songyzh Date: Thu, 13 Feb 2020 20:42:50 +0800 Subject: [PATCH 2/3] fix --- template.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/template.rs b/template.rs index 11411f01..9a860fe3 100644 --- a/template.rs +++ b/template.rs @@ -5,15 +5,15 @@ */ pub struct Solution {}__EXTRA_USE__ -// problem: __PROBLEM_LINK__ -// discuss: __DISCUSS_LINK__ - // submission codes start here __PROBLEM_DEFAULT_CODE__ // submission codes end +// problem: __PROBLEM_LINK__ +// discuss: __DISCUSS_LINK__ + #[cfg(test)] mod tests { use super::*; From e62f13afe8c69b69ca8b2949179c02ff706a7d58 Mon Sep 17 00:00:00 2001 From: songyzh Date: Fri, 14 Feb 2020 11:10:29 +0800 Subject: [PATCH 3/3] fix --- template.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/template.rs b/template.rs index 9a860fe3..11411f01 100644 --- a/template.rs +++ b/template.rs @@ -5,15 +5,15 @@ */ pub struct Solution {}__EXTRA_USE__ +// problem: __PROBLEM_LINK__ +// discuss: __DISCUSS_LINK__ + // submission codes start here __PROBLEM_DEFAULT_CODE__ // submission codes end -// problem: __PROBLEM_LINK__ -// discuss: __DISCUSS_LINK__ - #[cfg(test)] mod tests { use super::*;