Skip to content

Commit 7a1f807

Browse files
committed
Add links to problem description
1 parent ba7592a commit 7a1f807

35 files changed

+149
-122
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ serde = "1.0"
1010
serde_json = "1.0"
1111
serde_derive = "1.0"
1212
rand = "0.6.5"
13-
regex = "1.3.4"
13+
regex = "1"
1414

1515
[lib]
1616
doctest = false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Leetcode Solutions in Rust [![Build Status `master`](https://travis-ci.org/mapx/leetcode-rust.svg?branch=master)](https://travis-ci.org/mapx/leetcode-rust)
22

3-
A play yard for learning Rust as well as practising with leetcode problems. The problem fetching and testing framework comes from https://github.com/aylei/leetcode-rust
3+
A play yard for learning Rust as well as practising with leetcode problems. The problem fetching and testing framework came from https://github.com/aylei/leetcode-rust and evolves different features.
44

55
* Run `cargo run`, then provide an id to initialize the template submission file of "problem #id".
66
* Run `cargo test n{id}` to test the solution for "problem #id".

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ mod n1313_decompress_run_length_encoded_list;
3333
mod n1323_maximum_69_number;
3434
mod n1330_reverse_subarray_to_maximize_array_value;
3535
mod n1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance;
36-
mod n1344_jump_game_v;
36+
mod n1340_jump_game_v;

src/main.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate serde_derive;
44
extern crate serde_json;
55

66
mod problem;
7-
7+
use crate::problem::Problem;
88
use regex::Regex;
99
use std::env;
1010
use std::fs;
@@ -80,7 +80,9 @@ fn main() {
8080
&insert_return_in_code(&problem.return_type, &code.default_code),
8181
)
8282
.replace("__PROBLEM_ID__", &format!("{}", problem.question_id))
83-
.replace("__EXTRA_USE__", &parse_extra_use(&code.default_code));
83+
.replace("__EXTRA_USE__", &parse_extra_use(&code.default_code))
84+
.replace("__PROBLEM_LINK__", &parse_problem_link(&problem))
85+
.replace("__DISCUSS_LINK__", &parse_discuss_link(&problem));
8486

8587
let mut file = fs::OpenOptions::new()
8688
.write(true)
@@ -151,6 +153,17 @@ fn parse_extra_use(code: &str) -> String {
151153
extra_use_line
152154
}
153155

156+
fn parse_problem_link(problem: &Problem) -> String {
157+
format!("https://leetcode.com/problems/{}/", problem.title_slug)
158+
}
159+
160+
fn parse_discuss_link(problem: &Problem) -> String {
161+
format!(
162+
"https://leetcode.com/problems/{}/discuss/?currentPage=1&orderBy=most_votes",
163+
problem.title_slug
164+
)
165+
}
166+
154167
fn insert_return_in_code(return_type: &str, code: &str) -> String {
155168
let re = Regex::new(r"\{[ \n]+}").unwrap();
156169
match return_type {
@@ -195,7 +208,11 @@ fn insert_return_in_code(return_type: &str, code: &str) -> String {
195208

196209
fn build_desc(content: &str) -> String {
197210
// TODO: fix this shit
198-
content
211+
Regex::new("<font .*\">")
212+
.unwrap()
213+
.replace_all(&content, "`")
214+
.to_string()
215+
.replace("</font>", "`")
199216
.replace("<strong>", "")
200217
.replace("</strong>", "")
201218
.replace("<em>", "")
@@ -210,8 +227,8 @@ fn build_desc(content: &str) -> String {
210227
.replace("</ul>", "")
211228
.replace("<li>", "")
212229
.replace("</li>", "")
213-
.replace("<code>", "")
214-
.replace("</code>", "")
230+
.replace("<code>", "`")
231+
.replace("</code>", "`")
215232
.replace("<i>", "")
216233
.replace("</i>", "")
217234
.replace("<sub>", "")

src/n0001_two_sum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* Because nums[0] + nums[1] = 2 + 7 = 9,
1414
* return [0, 1].
1515
*
16-
*
16+
* Problem link: https://leetcode.com/problems/two-sum/
17+
* Discuss link: https://leetcode.com/problems/two-sum/discuss/?currentPage=1&orderBy=most_votes
1718
*/
1819
pub struct Solution {}
1920

src/n0002_add_two_numbers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* Output: 7 -> 0 -> 8
1313
* Explanation: 342 + 465 = 807.
1414
*
15-
*
15+
* Problem link: https://leetcode.com/problems/add-two-numbers/
16+
* Discuss link: https://leetcode.com/problems/add-two-numbers/discuss/?currentPage=1&orderBy=most_votes
1617
*/
1718
pub struct Solution {}
1819
use super::util::linked_list::{to_list, ListNode};

src/n0003_longest_substring_without_repeating_characters.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* </div>
3535
* </div>
3636
*
37+
* Problem link: https://leetcode.com/problems/longest-substring-without-repeating-characters/
38+
* Discuss link: https://leetcode.com/problems/longest-substring-without-repeating-characters/discuss/?currentPage=1&orderBy=most_votes
3739
*/
3840
pub struct Solution {}
3941

src/n0004_median_of_two_sorted_arrays.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@
88
* You may assume nums1 and nums2 cannot be both empty.
99
*
1010
* Example 1:
11-
*
12-
*
1311
* nums1 = [1, 3]
1412
* nums2 = [2]
1513
*
1614
* The median is 2.0
1715
*
18-
*
1916
* Example 2:
20-
*
21-
*
2217
* nums1 = [1, 2]
2318
* nums2 = [3, 4]
2419
*
2520
* The median is (2 + 3)/2 = 2.5
2621
*
27-
*
22+
* Problem link: https://leetcode.com/problems/median-of-two-sorted-arrays/
23+
* Discuss link: https://leetcode.com/problems/median-of-two-sorted-arrays/discuss/?currentPage=1&orderBy=most_votes
2824
*/
2925
pub struct Solution {}
3026

src/n0307_range_sum_query_mutable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
* The update(i, val) function modifies nums by updating the element at index i to val.
77
*
88
* Example:
9-
*
10-
*
119
* Given nums = [1, 3, 5]
1210
*
1311
* sumRange(0, 2) -> 9
1412
* update(1, 2)
1513
* sumRange(0, 2) -> 8
1614
*
17-
*
1815
* Note:
1916
*
2017
* <ol>
2118
* The array is only modifiable by the update function.
2219
* You may assume the number of calls to update and sumRange function is distributed evenly.
2320
* </ol>
2421
*
22+
* Problem link: https://leetcode.com/problems/range-sum-query-mutable/
23+
* Discuss link: https://leetcode.com/problems/range-sum-query-mutable/discuss/?currentPage=1&orderBy=most_votes
2524
*/
2625
pub struct Solution {}
2726

src/n0509_fibonacci_number.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
*
4343
* 0 &le; N &le; 30.
4444
*
45+
* Problem link: https://leetcode.com/problems/fibonacci-number/
46+
* Discuss link: https://leetcode.com/problems/fibonacci-number/discuss/?currentPage=1&orderBy=most_votes
4547
*/
4648
pub struct Solution {}
4749

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy