Skip to content

Commit 0414c9c

Browse files
authored
Merge pull request #3 from bestgopher/feature/new-script
Feature/new script
2 parents 265ac9c + 5558149 commit 0414c9c

35 files changed

+708
-1127
lines changed

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ git2 = "0.13.15"
1111
reqwest = { version = "0.10", features = ["blocking", "json"] }
1212
serde_json = "1.0"
1313
serde = { version = "1.0", features = ["derive"] }
14+
clap = "3.0.0-beta.2"
15+
tera = "1.12.1"
16+
lazy_static = "1.4.0"
17+
regex = "1"
18+
1419

1520
[[bin]]
1621
name ="leetcode"
17-
path ="src/main.rs"
22+
path = "src/main.rs"

README.md

Lines changed: 251 additions & 739 deletions
Large diffs are not rendered by default.

src/all.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use crate::file;
2+
3+
use std::sync::{Arc, Mutex};
4+
use std::thread;
5+
use crate::http::Resp;
6+
7+
8+
/// 重新格式化
9+
pub fn all() {
10+
let files = file::get_all_bin_file();
11+
12+
let v = Vec::<Resp>::with_capacity(files.len());
13+
14+
let x = Arc::new(Mutex::new(v));
15+
let mut handlers = vec![];
16+
17+
for i in 0..=files.len() / 10 {
18+
// 把files分块,分成10个文件一块
19+
let files = if i * 10 + 10 > files.len() {
20+
files[i * 10..files.len()].to_vec()
21+
} else {
22+
files[i * 10..i * 10 + 10].to_vec()
23+
};
24+
25+
let x = x.clone();
26+
27+
handlers.push(thread::spawn(move || {
28+
for i in files {
29+
println!("{} downloading", i);
30+
let resp = crate::http::get_question_info(&i);
31+
x.lock().unwrap().push(resp);
32+
}
33+
}))
34+
}
35+
36+
for i in handlers {
37+
i.join().unwrap();
38+
}
39+
40+
crate::file::write_readme(&mut *x.lock().unwrap());
41+
}

src/bin/boats-to-save-people.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Solution {
4444
count
4545
}
4646

47-
pub fn num_rescue_boats(mut people: Vec<i32>, limit: i32) -> i32 {
47+
pub fn num_rescue_boats(people: Vec<i32>, limit: i32) -> i32 {
4848
let mut v = vec![0; (limit + 1) as usize];
4949

5050
for i in people {

src/bin/climbing-stairs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ptr::hash;
1+
22

33
fn main() {}
44

@@ -12,7 +12,7 @@ impl Solution {
1212

1313
let (mut a, mut b) = (1, 2);
1414

15-
for i in 3..=n {
15+
for _i in 3..=n {
1616
let a1 = a;
1717
a = b;
1818
b = a1 + b;

src/bin/combination-sum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Solution {
2222
v.push(i);
2323
r.push(v);
2424
} else if i < target {
25-
let mut x = Self::calc(&candidates, target - i);
25+
let x = Self::calc(&candidates, target - i);
2626
for mut m in x {
2727
if !m.is_empty() {
2828
if i >= *m.last().unwrap() {

src/bin/construct-binary-search-tree-from-preorder-traversal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl TreeNode {
2323
}
2424

2525
use std::cell::RefCell;
26-
use std::ops::Deref;
26+
2727
use std::rc::Rc;
2828

2929
struct Solution;

src/bin/count-complete-tree-nodes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ impl TreeNode {
2121
}
2222
}
2323

24-
use std::arch::x86_64::_mm_xor_pd;
24+
2525
use std::cell::RefCell;
26-
use std::cmp::{max, min};
26+
2727
use std::rc::Rc;
2828

2929
impl Solution {
@@ -70,7 +70,7 @@ impl Solution {
7070
}
7171

7272
while max_count - min_count > 1 {
73-
let mut middle = (min_count + max_count) / 2;
73+
let middle = (min_count + max_count) / 2;
7474

7575
let e = exists(root.as_ref(), middle, level);
7676
if e {

src/bin/fei-bo-na-qi-shu-lie-lcof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl Solution {
88
return n;
99
}
1010
let (mut last, mut result) = (1, 1);
11-
for i in 2..n {
11+
for _i in 2..n {
1212
let result1 = result + last;
1313
last = result;
1414
result = result1 % 1000000007;

src/bin/find-k-closest-elements.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Solution {
2727
}
2828

2929
let index = Self::split(&arr, x);
30-
let (mut start, mut end, mut k) = (index, index, k as usize);
30+
let (mut start, mut end, k) = (index, index, k as usize);
3131
while end - start < k - 1 {
3232
if start == 0 {
3333
end += 1;

src/bin/group-anagrams.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Solution {
1616
.or_insert(vec![i]);
1717
}
1818

19-
hash.into_iter().map(|(x, y)| y).collect()
19+
hash.into_iter().map(|(_x, y)| y).collect()
2020
}
2121

2222
// 计算字母出现的个数
@@ -37,6 +37,6 @@ impl Solution {
3737
}
3838
}
3939

40-
hash.into_iter().map(|(x, y)| y).collect()
40+
hash.into_iter().map(|(_x, y)| y).collect()
4141
}
4242
}

src/bin/kth-largest-element-in-an-array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Solution {
1717
}
1818

1919
fn heapify(nums: &mut [i32]) {
20-
let mut index = (nums.len() - 1) / 2;
20+
let index = (nums.len() - 1) / 2;
2121

2222
for i in (0..=index).rev() {
2323
Self::down_heap(nums, i);

src/bin/least-number-of-unique-integers-after-k-removals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl Solution {
1010
h.entry(i).and_modify(|x| *x += 1).or_insert(1);
1111
}
1212

13-
let mut s = h.iter().map(|(x, y)| *y).collect::<Vec<i32>>();
13+
let mut s = h.iter().map(|(_x, y)| *y).collect::<Vec<i32>>();
1414
s.sort();
1515

1616
let (mut l, mut k) = (h.len(), k);

src/bin/letter-case-permutation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Solution {
1111

1212
fn func(s: String, v: &mut Vec<String>, index: usize) {
1313
let mut new_s = s.clone();
14-
let mut new_s = unsafe { new_s.as_bytes_mut() };
14+
let new_s = unsafe { new_s.as_bytes_mut() };
1515
v.push(s);
1616
if index == new_s.len() {
1717
return;

src/bin/longest-substring-without-repeating-characters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
22

33
fn main() {
44
assert_eq!(2, Solution::length_of_longest_substring("aab".to_string()));

src/bin/magical-string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fn main() {}
33
struct Solution;
44

55
impl Solution {
6-
pub fn magical_string(mut n: i32) -> i32 {
6+
pub fn magical_string(n: i32) -> i32 {
77
if n == 0 {
88
return 0;
99
}

src/bin/majority-element-ii.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ impl Solution {
2222
}
2323

2424
m.iter()
25-
.filter(|(&x, &y)| y > length)
26-
.map(|(&x, &y)| x)
25+
.filter(|(&_x, &y)| y > length)
26+
.map(|(&x, &_y)| x)
2727
.collect()
2828
}
2929

@@ -106,7 +106,7 @@ impl Solution {
106106
None
107107
})
108108
.filter(|x| x.is_some())
109-
.map(|mut x| x.unwrap())
109+
.map(|x| x.unwrap())
110110
.collect()
111111
}
112112
}

src/bin/maximum-population-year.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn maximum_population(logs: Vec<Vec<i32>>) -> i32 {
7+
let mut v = vec![0; 1000];
8+
9+
for i in logs {
10+
for x in (i[0] - 1950) as usize..(i[1] - 1950) as usize {
11+
v[x] += 1;
12+
}
13+
}
14+
15+
let mut max = 0;
16+
17+
for i in 1..v.len() {
18+
max = if v[i] > v[max] {
19+
i
20+
} else {
21+
max
22+
}
23+
}
24+
25+
max as i32 + 1950
26+
}
27+
}

src/bin/maximum-product-of-word-lengths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl Solution {
88

99
for i in 0..words.len() {
1010
for &j in words[i].as_bytes() {
11-
v[i] |= (1 << (j - b'a'));
11+
v[i] |= 1 << (j - b'a');
1212
}
1313
}
1414

src/bin/number-complement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88
struct Solution;
99

1010
impl Solution {
11-
pub fn find_complement(mut num: i32) -> i32 {
11+
pub fn find_complement(num: i32) -> i32 {
1212
let lz = num.leading_zeros();
1313
!num << lz >> lz
1414
}

src/bin/qiu-12n-lcof.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ impl Solution {
66
pub fn sum_nums(n: i32) -> i32 {
77
let mut n = n;
88
// 利用布尔短路的思想,n == 0 时,不会允许&&后面的表达式
9-
n > 0 && (n += Self::sum_nums(n - 1)) == ();
9+
if n > 0 {
10+
n += Self::sum_nums(n - 1);
11+
}
12+
1013
n
1114
}
1215
}

src/bin/reverse-linked-list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Solution {
3434
let mut root = v.pop().unwrap();
3535
let mut s = &mut root;
3636
while !v.is_empty() {
37-
let mut node = v.pop().unwrap();
37+
let node = v.pop().unwrap();
3838
s.as_mut().unwrap().next = node;
3939
s = &mut s.as_mut().unwrap().next;
4040
}

src/bin/reverse-words-in-a-string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ impl Solution {
77
if s.is_empty() {
88
return s;
99
}
10-
let mut s = s.as_bytes();
10+
let s = s.as_bytes();
1111
let (mut start, mut end) = (0, s.len() - 1);
1212

1313
for i in 0..s.len() {

src/bin/robot-bounded-in-circle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct Solution;
66

77
impl Solution {
88
/// 只有(x,y)不是原点,并且方向和原来的方向一致,最后才回不去
9-
pub fn is_robot_bounded(mut instructions: String) -> bool {
9+
pub fn is_robot_bounded(instructions: String) -> bool {
1010
let mut start = (0, 0);
1111
let mut direction = 0u8; // 当前的方向,0为向前,1为向左,2为向后,3为向右
1212

src/bin/search-in-rotated-sorted-array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os::macos::raw::stat;
1+
22

33
fn main() {
44
assert_eq!(4, Solution::search(vec![4, 5, 6, 7, 8, 1, 2, 3], 8));

src/bin/sqrtx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct Solution;
44

55
impl Solution {
66
pub fn my_sqrt(x: i32) -> i32 {
7-
let mut s = x as f64;
7+
let s = x as f64;
88
let mut x1 = x as f64;
99

1010
while (s - x1 * x1).abs() > 0.1 {

src/bin/summary-ranges.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use serde_json::ser::CharEscape::Solidus;
1+
22

33
fn main() {
44
println!("{:?}", Solution::summary_ranges(vec![0, 1, 2, 4, 5, 7]));

src/bin/swapping-nodes-in-a-linked-list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ impl Solution {
5858
index += 1;
5959
}
6060

61-
let f = k_node.unwrap().val;
62-
let s = slow.unwrap().val;
61+
let _f = k_node.unwrap().val;
62+
let _s = slow.unwrap().val;
6363

6464
head
6565
}

0 commit comments

Comments
 (0)