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__