Skip to content

Commit 8dde600

Browse files
committed
Apply cargo clippy --fix
1 parent 2ea995b commit 8dde600

File tree

7 files changed

+14
-19
lines changed

7 files changed

+14
-19
lines changed

src/leetcode/interview/amazon/reorder_log_files.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ impl Solution {
66
let mut digit_logs = vec![];
77

88
for log in logs {
9-
let chunks = log.split(" ").map(|s| s.to_string()).collect::<Vec<String>>();
9+
let chunks = log.split(' ').map(|s| s.to_string()).collect::<Vec<String>>();
1010
let id = chunks[0].clone();
1111
let msg = &chunks[1..];
1212
let kind = {
@@ -27,7 +27,7 @@ impl Solution {
2727
letter_logs.sort_by(|a, b| {
2828
let (id_a, msg_a) = a;
2929
let (id_b, msg_b) = b;
30-
msg_a.cmp(&msg_b).then_with(|| id_a.cmp(&id_b))
30+
msg_a.cmp(msg_b).then_with(|| id_a.cmp(id_b))
3131
});
3232

3333
letter_logs.into_iter().map(|(id, msg)| format!("{} {}", id, msg)).into_iter().chain(digit_logs).collect()

src/leetcode/interview/robinhood/alert_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Solution {
3636
}
3737
});
3838

39-
let mut ans = ans.iter().map(|f| f.clone()).collect::<Vec<String>>();
39+
let mut ans = ans.iter().cloned().collect::<Vec<String>>();
4040
ans.sort_unstable();
4141
ans
4242
}

src/leetcode/problem/climb_stairs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl Solution {
1010
for i in 4..=n as usize {
1111
dp[i] = dp[i - 1] + dp[i - 2];
1212
}
13-
return dp[n as usize];
13+
dp[n as usize]
1414
}
1515
}
1616

src/leetcode/problem/exist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{HashSet, VecDeque};
22

33
impl Solution {
44
pub fn exist(board: Vec<Vec<char>>, word: String) -> bool {
5-
if word.len() == 0 {
5+
if word.is_empty() {
66
return true;
77
}
88

@@ -30,7 +30,7 @@ impl Solution {
3030
seen[i as usize][j as usize] = 1;
3131
let dirs = vec![(0, 1), (0, -1), (1, 0), (-1, 0)];
3232
for dir in dirs.iter() {
33-
let pos = (i + dir.0, j + dir.1);
33+
let _pos = (i + dir.0, j + dir.1);
3434
dfs(board, word, idx + 1, (i + dir.0, j + dir.1), seen, ans);
3535
}
3636
seen[i as usize][j as usize] = 0;

src/leetcode/problem/implement_trie_prefix_tree.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@ impl Trie {
2222
fn insert(&mut self, word: String) {
2323
let mut current = &mut self.root;
2424
for c in word.chars() {
25-
if !current.children.contains_key(&c) {
26-
current.children.insert(
27-
c,
28-
CharNode {
25+
current.children.entry(c).or_insert(CharNode {
2926
char: c,
3027
is_word: false,
3128
children: HashMap::new(),
32-
},
33-
);
34-
}
29+
});
3530
current = current.children.get_mut(&c).unwrap();
3631
}
3732
current.is_word = true;

src/leetcode/problem/solve_n_queens.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ impl Solution {
3131
}
3232
}
3333

34-
return true;
34+
true
3535
}
3636

3737
let mut ans: Vec<Vec<Vec<i32>>> = vec![];
3838
fn backtracking(ans: &mut Vec<Vec<Vec<i32>>>, board: &mut Vec<Vec<i32>>, n: usize, placed: usize, i: usize, j: usize) {
3939
if placed == n {
4040
ans.push(board.clone());
41-
return;
41+
4242
} else if i == n {
43-
return;
43+
4444
} else if j == n {
4545
backtracking(ans, board, n, placed, i + 1, 0);
4646
} else {

src/leetcode/problem/total_n_queens.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ impl Solution {
3131
}
3232
}
3333

34-
return true;
34+
true
3535
}
3636

3737
let mut ans: Vec<Vec<Vec<i32>>> = vec![];
3838
fn backtracking(ans: &mut Vec<Vec<Vec<i32>>>, board: &mut Vec<Vec<i32>>, n: usize, placed: usize, i: usize, j: usize) {
3939
if placed == n {
4040
ans.push(board.clone());
41-
return;
41+
4242
} else if i == n {
43-
return;
43+
4444
} else if j == n {
4545
backtracking(ans, board, n, placed, i + 1, 0);
4646
} else {

0 commit comments

Comments
 (0)