Skip to content

Commit 4fb84c1

Browse files
authoredOct 16, 2019
Merge pull request aylei#15 from mapx/for_upstream_pr
Fix the inconsistency
2 parents 3852b67 + ed07425 commit 4fb84c1

File tree

227 files changed

+5041
-3950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+5041
-3950
lines changed
 

‎src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ mod n0215_kth_largest_element_in_an_array;
186186
mod n0216_combination_sum_iii;
187187
mod n0217_contains_duplicate;
188188
mod n0218_the_skyline_problem;
189-
mod n0220_contains_duplicate_iii;
190189
mod n0219_contains_duplicate_ii;
190+
mod n0220_contains_duplicate_iii;
191191
mod n0221_maximal_square;
192-
mod n0223_rectangle_area;
193192
mod n0222_count_complete_tree_nodes;
193+
mod n0223_rectangle_area;
194194
mod n0224_basic_calculator;
195195
mod n0225_implement_stack_using_queues;
196196
mod n0226_invert_binary_tree;
@@ -227,12 +227,14 @@ mod n0300_longest_increasing_subsequence;
227227
mod n0301_remove_invalid_parentheses;
228228
mod n0303_range_sum_query_immutable;
229229
mod n0304_range_sum_query_2d_immutable;
230-
mod n1009_pancake_sorting;
231230
mod n0306_additive_number;
232231
mod n0307_range_sum_query_mutable;
233232
mod n0309_best_time_to_buy_and_sell_stock_with_cooldown;
234233
mod n0310_minimum_height_trees;
235234
mod n0312_burst_balloons;
236235
mod n0313_super_ugly_number;
237-
mod n1013_fibonacci_number;
238236
mod n0792_binary_search;
237+
mod n1009_pancake_sorting;
238+
mod n1013_fibonacci_number;
239+
mod n1071_binary_prefix_divisible_by_5;
240+
mod n1127_last_stone_weight;

‎src/main.rs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ mod problem;
77

88
use std::env;
99
use std::fs;
10-
use std::path::{Path};
11-
use std::io::Write;
1210
use std::io;
11+
use std::io::Write;
12+
use std::path::Path;
1313

1414
/// main() helps to generate the submission template .rs
1515
fn main() {
1616
println!("Welcome to leetcode-rust system.");
1717
let mut solved_ids = get_solved_ids();
1818
loop {
19-
println!("Please enter a problem id, or enter \"random\" to generate a random problem.");
19+
println!("Please enter a frontend problem id, or \"random\" to generate a random one.");
2020
let mut is_random = false;
21-
let mut id :u32 = 0;
21+
let mut id: u32 = 0;
2222
let mut id_arg = String::new();
23-
io::stdin().read_line(&mut id_arg)
23+
io::stdin()
24+
.read_line(&mut id_arg)
2425
.expect("Failed to read line");
2526
let id_arg = id_arg.trim();
2627
match id_arg {
@@ -29,23 +30,30 @@ fn main() {
2930
id = generate_random_id(&solved_ids);
3031
is_random = true;
3132
println!("Generate random problem: {}", &id);
32-
},
33+
}
3334
_ => {
34-
id = id_arg.parse::<u32>().expect(&format!("not a number: {}", id_arg));
35+
id = id_arg
36+
.parse::<u32>()
37+
.expect(&format!("not a number: {}", id_arg));
3538
if solved_ids.contains(&id) {
36-
println!("The problem you chose is invalid (the problem may have been solved \
37-
or may have no rust version).");
39+
println!(
40+
"The problem you chose is invalid (the problem may have been solved \
41+
or may have no rust version)."
42+
);
3843
continue;
3944
}
4045
}
4146
}
4247

43-
let problem = problem::get_problem(id)
44-
.expect(&format!("Error: failed to get problem #{} \
45-
(The problem may be paid-only or may not be exist).",
46-
id));
47-
let code = problem.code_definition.iter()
48-
.filter(|&d| { d.value == "rust" })
48+
let problem = problem::get_problem(id).expect(&format!(
49+
"Error: failed to get problem #{} \
50+
(The problem may be paid-only or may not be exist).",
51+
id
52+
));
53+
let code = problem
54+
.code_definition
55+
.iter()
56+
.filter(|&d| d.value == "rust")
4957
.next();
5058
if code.is_none() {
5159
println!("Problem {} has no rust version.", &id);
@@ -54,7 +62,11 @@ fn main() {
5462
}
5563
let code = code.unwrap();
5664

57-
let file_name = format!("n{:04}_{}", problem.question_id, problem.title_slug.replace("-", "_"));
65+
let file_name = format!(
66+
"n{:04}_{}",
67+
problem.question_id,
68+
problem.title_slug.replace("-", "_")
69+
);
5870
let file_path = Path::new("./src").join(format!("{}.rs", file_name));
5971
if file_path.exists() {
6072
panic!("problem already initialized");
@@ -88,17 +100,20 @@ fn main() {
88100
}
89101
}
90102

91-
fn generate_random_id(except_ids : &Vec<u32>) -> u32 {
92-
use std::fs;
103+
fn generate_random_id(except_ids: &Vec<u32>) -> u32 {
93104
use rand::Rng;
105+
use std::fs;
94106
let mut rng = rand::thread_rng();
95107
loop {
96-
let res :u32 = rng.gen_range(1, 1106);
108+
let res: u32 = rng.gen_range(1, 1106);
97109
if !except_ids.contains(&res) {
98110
return res;
99111
}
100-
println!("Generate a random num ({}), but it is invalid (the problem may have been solved \
101-
or may have no rust version). Regenerate..", res);
112+
println!(
113+
"Generate a random num ({}), but it is invalid (the problem may have been solved \
114+
or may have no rust version). Regenerate..",
115+
res
116+
);
102117
}
103118
}
104119

0 commit comments

Comments
 (0)
Please sign in to comment.