Skip to content

Commit c001fb5

Browse files
committed
clippy fix
1 parent 3eee450 commit c001fb5

35 files changed

+285
-477
lines changed

src/array/ext/math.rs

+19-28
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ pub fn shuffle(nums: Vec<i32>, n: i32) -> Vec<i32> {
7070
let mut nums = nums;
7171
let n = n as usize;
7272
for i in 0..n {
73-
nums[2 * i] = nums[2 * i] | ((nums[i] & 1023) << 10);
74-
nums[2 * i + 1] = nums[2 * i + 1] | ((nums[i + n] & 1023) << 10);
73+
nums[2 * i] |= (nums[i] & 1023) << 10;
74+
nums[2 * i + 1] |= (nums[i + n] & 1023) << 10;
7575
}
7676
nums.iter_mut().for_each(|num| {
77-
*num = *num >> 10;
77+
*num >>= 10;
7878
});
7979
nums
8080
}
@@ -101,7 +101,7 @@ pub fn num_special(mat: Vec<Vec<i32>>) -> i32 {
101101
return false;
102102
}
103103
}
104-
return true;
104+
true
105105
}
106106

107107
let mut cnt = 0;
@@ -150,7 +150,6 @@ pub fn construct_array(n: i32, k: i32) -> Vec<i32> {
150150
/// [412. Fizz Buzz](https://leetcode.cn/problems/fizz-buzz/)
151151
pub fn fizz_buzz(n: i32) -> Vec<String> {
152152
(1..=n)
153-
.into_iter()
154153
.map(|num| {
155154
if num % 3 == 0 && num % 5 == 0 {
156155
"FizzBuzz".to_string()
@@ -194,7 +193,7 @@ pub fn fizz_buzz(n: i32) -> Vec<String> {
194193
/// 注意: 如果原本为0, 这时 `31 - (leading_zero)`可能有溢出
195194
///
196195
pub fn number_of_steps(num: i32) -> i32 {
197-
(num.count_ones() + 31u32.checked_sub(num.leading_zeros()).unwrap_or(0)) as i32
196+
(num.count_ones() + 31u32.saturating_sub(num.leading_zeros())) as i32
198197
}
199198

200199
/// [829. 连续整数求和](https://leetcode.cn/problems/consecutive-numbers-sum/)
@@ -329,15 +328,15 @@ pub fn unique_letter_string(s: String) -> i32 {
329328
let pos = pos as i32;
330329
if curr_pos[i] > -1 {
331330
// 这个字符之前出现过, 这时的pos对应上述推导中的后一个
332-
ans = ans + (pos - curr_pos[i]) * (curr_pos[i] - last_pos[i]);
331+
ans += (pos - curr_pos[i]) * (curr_pos[i] - last_pos[i]);
333332
}
334333
last_pos[i] = curr_pos[i];
335334
curr_pos[i] = pos;
336335
}
337336
// 对于只出现过一次的字符, 上面循环统计不到, 即等效 后一个 的位置为字符结尾
338337
for (last, curr) in last_pos.into_iter().zip(curr_pos.into_iter()) {
339338
if curr > -1 {
340-
ans = ans + (curr - last) * (s.len() as i32 - curr);
339+
ans += (curr - last) * (s.len() as i32 - curr);
341340
}
342341
}
343342
ans
@@ -363,7 +362,7 @@ pub fn largest_overlap(img1: Vec<Vec<i32>>, img2: Vec<Vec<i32>>) -> i32 {
363362
}
364363
}
365364
}
366-
delta.values().into_iter().max().copied().unwrap_or(0)
365+
delta.values().max().copied().unwrap_or(0)
367366
}
368367

369368
/// [836. 矩形重叠](https://leetcode.cn/problems/rectangle-overlap/)
@@ -488,15 +487,15 @@ pub fn mirror_reflection(p: i32, q: i32) -> i32 {
488487
} else if (d / q) % 2 == 0 {
489488
return 2;
490489
}
491-
return 1;
490+
1
492491
}
493492

494493
fn gcd(a: i32, b: i32) -> i32 {
495494
let (m, n) = (a.max(b), a.min(b));
496495
if n == 0 {
497496
return m;
498497
}
499-
return gcd(n, m % n);
498+
gcd(n, m % n)
500499
}
501500
fn lcm(a: i32, b: i32) -> i32 {
502501
a * b / gcd(a, b)
@@ -511,7 +510,7 @@ pub fn transpose(matrix: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
511510
ret[j][i] = matrix[i][j];
512511
}
513512
}
514-
return ret;
513+
ret
515514
}
516515

517516
/// [LCP 06. 拿硬币](https://leetcode.cn/problems/na-ying-bi)
@@ -882,8 +881,7 @@ mod tests {
882881
expect: &'static [i32],
883882
}
884883

885-
vec![
886-
TestCase {
884+
[TestCase {
887885
name: "basic 1",
888886
n: 3,
889887
k: 1,
@@ -894,8 +892,7 @@ mod tests {
894892
n: 3,
895893
k: 2,
896894
expect: &[1, 3, 2],
897-
},
898-
]
895+
}]
899896
.iter()
900897
.for_each(|testcase| {
901898
let acutal = construct_array(testcase.n, testcase.k);
@@ -911,8 +908,7 @@ mod tests {
911908
expect: i32,
912909
}
913910

914-
vec![
915-
TestCase {
911+
[TestCase {
916912
name: "basic 1",
917913
mat: &[&[1, 0, 0], &[0, 0, 1], &[1, 0, 0]],
918914
expect: 1,
@@ -926,8 +922,7 @@ mod tests {
926922
name: "basic 3",
927923
mat: &[&[0, 0, 0, 1], &[1, 0, 0, 0], &[0, 1, 1, 0], &[0, 0, 0, 0]],
928924
expect: 2,
929-
},
930-
]
925+
}]
931926
.iter()
932927
.for_each(|testcase| {
933928
let mat = testcase.mat.iter().map(|line| line.to_vec()).collect();
@@ -945,8 +940,7 @@ mod tests {
945940
expect: &'static [i32],
946941
}
947942

948-
vec![
949-
TestCase {
943+
[TestCase {
950944
name: "basic 1",
951945
nums: &[2, 5, 1, 3, 4, 7],
952946
n: 3,
@@ -963,8 +957,7 @@ mod tests {
963957
nums: &[1, 1, 2, 2],
964958
n: 2,
965959
expect: &[1, 2, 1, 2],
966-
},
967-
]
960+
}]
968961
.iter()
969962
.for_each(|testcase| {
970963
let actual = shuffle(testcase.nums.to_vec(), testcase.n);
@@ -980,8 +973,7 @@ mod tests {
980973
expect: i32,
981974
}
982975

983-
vec![
984-
TestCase {
976+
[TestCase {
985977
name: "basic",
986978
nums: &[1, 2, 3],
987979
expect: 2,
@@ -1000,8 +992,7 @@ mod tests {
1000992
name: "fix 1",
1001993
nums: &[1],
1002994
expect: 0,
1003-
},
1004-
]
995+
}]
1005996
.iter()
1006997
.for_each(|testcase| {
1007998
let actual = min_moves2(testcase.nums.to_vec());

src/array/ext/quick.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ mod tests {
172172
expect: &'static [&'static [i32]],
173173
}
174174

175-
vec![
176-
TestCase {
175+
[TestCase {
177176
name: "basic",
178177
intervals: &[&[1, 3], &[2, 6], &[8, 10], &[15, 18]],
179178
expect: &[&[1, 6], &[8, 10], &[15, 18]],
@@ -182,8 +181,7 @@ mod tests {
182181
name: "basic 2",
183182
intervals: &[&[1, 4], &[4, 5]],
184183
expect: &[&[1, 5]],
185-
},
186-
]
184+
}]
187185
.iter()
188186
.for_each(|testcase| {
189187
let intervals = testcase.intervals.iter().map(|rng| rng.to_vec()).collect();
@@ -200,8 +198,7 @@ mod tests {
200198
k: i32,
201199
expect: i32,
202200
}
203-
vec![
204-
TestCase {
201+
[TestCase {
205202
name: "basic",
206203
nums: &[3, 2, 1, 5, 6, 4],
207204
k: 2,
@@ -212,8 +209,7 @@ mod tests {
212209
nums: &[3, 2, 3, 1, 2, 4, 5, 5, 6],
213210
k: 4,
214211
expect: 4,
215-
},
216-
]
212+
}]
217213
.iter()
218214
.for_each(|testcase| {
219215
let actual = find_kth_largest(testcase.nums.to_vec(), testcase.k);
@@ -228,8 +224,7 @@ mod tests {
228224
nums: &'static [i32],
229225
}
230226

231-
vec![
232-
TestCase {
227+
[TestCase {
233228
name: "basic",
234229
nums: &[5, 2, 3, 1],
235230
},
@@ -240,8 +235,7 @@ mod tests {
240235
TestCase {
241236
name: "fix 1",
242237
nums: &[-1, 2, -8, -10],
243-
},
244-
]
238+
}]
245239
.iter()
246240
.for_each(|testcase| {
247241
let mut nums = testcase.nums.to_vec();

src/array/ext/random/random0.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub mod array {
165165
expect: i32,
166166
}
167167

168-
vec![TestCase {
168+
[TestCase {
169169
name: "basic",
170170
w: &[1],
171171
expect: 0,
@@ -258,7 +258,7 @@ pub mod set {
258258
queries: &'static [Op],
259259
}
260260

261-
vec![TestCase {
261+
[TestCase {
262262
name: "basic",
263263
queries: &[
264264
Op::Insert((1, true)),
@@ -299,7 +299,7 @@ mod tests {
299299
#[test]
300300
#[ignore]
301301
fn test_show_binary_search() {
302-
let v = vec![1, 2, 3, 4, 5, 6, 9];
302+
let v = [1, 2, 3, 4, 5, 6, 9];
303303
println!("1: {}", v.binary_search(&1).unwrap());
304304
println!("5: {}", v.binary_search(&5).unwrap());
305305
println!("9: {}", v.binary_search(&9).unwrap());

src/array/ext/random/random1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod array {
4444
nums: &'static [i32],
4545
}
4646

47-
vec![TestCase {
47+
[TestCase {
4848
name: "basic",
4949
nums: &[1, 2, 3, 3, 3],
5050
}]

src/array/ext/random/random2.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ pub mod black_random {
7878
expect_in: &'static [i32],
7979
}
8080

81-
vec![
82-
TestCase {
81+
[TestCase {
8382
name: "basic",
8483
n: 7,
8584
blacklist: &[2, 3, 5],
@@ -90,8 +89,7 @@ pub mod black_random {
9089
n: 4,
9190
blacklist: &[2, 1],
9291
expect_in: &[0, 3],
93-
},
94-
]
92+
}]
9593
.iter()
9694
.for_each(|testcase| {
9795
let s = Solution::new(testcase.n, testcase.blacklist.to_vec());
@@ -159,7 +157,7 @@ pub mod black_random {
159157
expect_in: &'static [i32],
160158
}
161159

162-
vec![TestCase {
160+
[TestCase {
163161
name: "basic",
164162
n: 7,
165163
blacklist: &[2, 3, 5],

src/array/ext/rotate.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ mod tests {
263263
expect: &'static [i32],
264264
}
265265

266-
vec![
267-
TestCase {
266+
[TestCase {
268267
name: "basic 1",
269268
mat: &[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]],
270269
expect: &[1, 2, 4, 7, 5, 3, 6, 8, 9],
@@ -273,8 +272,7 @@ mod tests {
273272
name: "basic 2",
274273
mat: &[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]],
275274
expect: &[1, 2, 4, 7, 5, 3, 6, 8, 9],
276-
},
277-
]
275+
}]
278276
.iter()
279277
.for_each(|testcase| {
280278
let mat = testcase.mat.iter().map(|line| line.to_vec()).collect();
@@ -291,8 +289,7 @@ mod tests {
291289
expect: &'static [&'static [i32]],
292290
}
293291

294-
vec![
295-
TestCase {
292+
[TestCase {
296293
name: "basic",
297294
n: 3,
298295
expect: &[&[1, 2, 3], &[8, 9, 4], &[7, 6, 5]],
@@ -301,8 +298,7 @@ mod tests {
301298
name: "basic 2",
302299
n: 1,
303300
expect: &[&[1]],
304-
},
305-
]
301+
}]
306302
.iter()
307303
.for_each(|testcase| {
308304
let actual = generate_matrix(testcase.n);
@@ -318,8 +314,7 @@ mod tests {
318314
expect: &'static [i32],
319315
}
320316

321-
vec![
322-
TestCase {
317+
[TestCase {
323318
name: "basic",
324319
matrix: &[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]],
325320
expect: &[1, 2, 3, 6, 9, 8, 7, 4, 5],
@@ -333,8 +328,7 @@ mod tests {
333328
name: "fix 1",
334329
matrix: &[&[3], &[2]],
335330
expect: &[3, 2],
336-
},
337-
]
331+
}]
338332
.iter()
339333
.for_each(|testcase| {
340334
let matrix = testcase.matrix.iter().map(|x| x.to_vec()).collect();
@@ -351,7 +345,7 @@ mod tests {
351345
expect: &'static [&'static [i32]],
352346
}
353347

354-
vec![TestCase {
348+
[TestCase {
355349
name: "basic",
356350
matrix: &[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]],
357351
expect: &[&[7, 4, 1], &[8, 5, 2], &[9, 6, 3]],
@@ -373,8 +367,7 @@ mod tests {
373367
expect: &'static str,
374368
}
375369

376-
vec![
377-
TestCase {
370+
[TestCase {
378371
name: "basic",
379372
s: "abcdefg",
380373
n: 2,
@@ -385,8 +378,7 @@ mod tests {
385378
s: "lrloseumgh",
386379
n: 6,
387380
expect: "umghlrlose",
388-
},
389-
]
381+
}]
390382
.iter()
391383
.for_each(|testcase| {
392384
let s = testcase.s.to_string();

src/array/ext/topological.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub fn check_if_prerequisite(
380380
query_map[require][want] = 1;
381381
for col in 0..query_map.len() {
382382
// 将require的前置, 也加入到want的前置中
383-
query_map[col][want] = query_map[col][want] | query_map[col][require];
383+
query_map[col][want] |= query_map[col][require];
384384
}
385385

386386
in_degrees[want] -= 1;

0 commit comments

Comments
 (0)