Skip to content

Commit bf03c66

Browse files
committed
cargo clippy project
1 parent f5fdb99 commit bf03c66

31 files changed

+293
-249
lines changed

README.md

Lines changed: 248 additions & 204 deletions
Large diffs are not rendered by default.

src/all.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::http::Resp;
99
pub fn all() {
1010
let files = file::get_all_bin_file();
1111

12-
let mut v = Vec::<Resp>::with_capacity(files.len());
12+
let v = Vec::<Resp>::with_capacity(files.len());
1313

1414
let x = Arc::new(Mutex::new(v));
1515
let mut handlers = vec![];
@@ -26,14 +26,15 @@ pub fn all() {
2626

2727
handlers.push(thread::spawn(move || {
2828
for i in files {
29+
println!("{} downloading", i);
2930
let resp = crate::http::get_question_info(&i);
3031
x.lock().unwrap().push(resp);
3132
}
3233
}))
3334
}
3435

3536
for i in handlers {
36-
i.join();
37+
i.join().unwrap();
3738
}
3839

3940
crate::file::write_readme(&mut *x.lock().unwrap());

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-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
}

src/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn write_question(resp: Resp) {
5252
for i in resp.data.question.code_snippets {
5353
if i.lang == "Rust" {
5454
s.push_str(i.code.replace("↵", "\n").as_str());
55-
s.push_str("\n");
55+
s.push('\n');
5656
break;
5757
}
5858
}

src/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ lazy_static! {
88
static ref RE: Regex = Regex::new(r".*?/problems/(.*?)/").unwrap();
99
}
1010

11-
const URL: &'static str = "https://leetcode-cn.com/graphql/";
11+
const URL: &str = "https://leetcode-cn.com/graphql/";
1212

1313
#[derive(Deserialize, Serialize, Debug)]
1414
pub struct Ques {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn run() {
2626
Ok(x) => new::new(x),
2727
Err(_) => println!("please input the name of question")
2828
}
29-
} else if let Some(_) = matches.subcommand_matches("all") {
29+
} else if matches.subcommand_matches("all").is_some() {
3030
all::all();
3131
} else {
3232
git::push();

src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use leetcode;
2-
31
fn main() {
42
leetcode::run()
53
}

src/render.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use lazy_static::lazy_static;
2-
use tera::{Tera, Context, Error as TeraError, ErrorKind, Result as TeraResult};
2+
use tera::{Tera, Context, Result as TeraResult};
33

44
/// 模板内容
5-
const TEMPLATE_STR: &'static str = r"# leetcode
5+
const TEMPLATE_STR: &str = r"# leetcode
66
77
当前已刷:{{ datas | length }}
88
@@ -13,10 +13,8 @@ const TEMPLATE_STR: &'static str = r"# leetcode
1313
{% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}) |
1414
{% endfor %}";
1515

16-
static A: &str = "";
17-
1816
/// 模板名字
19-
const TEMPLATE_NAME: &'static str = "leetcode";
17+
const TEMPLATE_NAME: &str = "leetcode";
2018

2119
lazy_static!(
2220
/// 用于渲染的模板
@@ -29,7 +27,7 @@ lazy_static!(
2927

3028

3129
/// 把传入的内容渲染为模板内容
32-
pub fn render(data: &Vec<crate::http::Resp>) -> TeraResult<String> {
30+
pub fn render(data: &[crate::http::Resp]) -> TeraResult<String> {
3331
let mut ctx = Context::new();
3432
ctx.insert("datas", data);
3533

@@ -51,7 +49,7 @@ mod tests {
5149
title_slug: "aaa".to_string(),
5250
translated_title: "中国".to_string(),
5351
code_snippets: vec![],
54-
difficulty: String::new();
52+
difficulty: String::new(),
5553
}
5654
},
5755
},

0 commit comments

Comments
 (0)