Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1bf1ee4

Browse files
committed
Apply cargo clippy --fix
1 parent 1d3cc9a commit 1bf1ee4

File tree

13 files changed

+48
-60
lines changed

13 files changed

+48
-60
lines changed

‎src/leetcode/challenge/can_partition_k_subsets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl Solution {
88
}
99
let target = sum / k;
1010

11-
nums.sort();
11+
nums.sort_unstable();
1212
if nums[nums.len() - 1] > target {
1313
return false;
1414
}

‎src/leetcode/challenge/cherry_pickup.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ impl Solution {
2222
return *memo.get(key).unwrap();
2323
}
2424

25-
let dd = dp(&grid, &n, i1 + 1, j1, i2 + 1, j2, memo);
26-
let dr = dp(&grid, &n, i1 + 1, j1, i2, j2 + 1, memo);
27-
let rd = dp(&grid, &n, i1, j1 + 1, i2 + 1, j2, memo);
28-
let rr = dp(&grid, &n, i1, j1 + 1, i2, j2 + 1, memo);
25+
let dd = dp(grid, n, i1 + 1, j1, i2 + 1, j2, memo);
26+
let dr = dp(grid, n, i1 + 1, j1, i2, j2 + 1, memo);
27+
let rd = dp(grid, n, i1, j1 + 1, i2 + 1, j2, memo);
28+
let rr = dp(grid, n, i1, j1 + 1, i2, j2 + 1, memo);
2929

3030
let comb = i32::max(dd, i32::max(dr, i32::max(rd, rr)));
3131

3232
let out;
3333
if comb == -1 {
3434
out = -1;
35+
} else if i1 == i2 && j1 == j2 {
36+
out = comb + grid[i1][j1];
3537
} else {
36-
if i1 == i2 && j1 == j2 {
37-
out = comb + grid[i1][j1];
38-
} else {
39-
out = comb + grid[i1][j1] + grid[i2][j2];
40-
}
38+
out = comb + grid[i1][j1] + grid[i2][j2];
4139
}
4240

4341
memo.insert(*key, out);

‎src/leetcode/challenge/max_sub_array_len.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ impl Solution {
1717
max_length = max_length.max(i - j);
1818
}
1919

20-
if !sum_to_index_mapping.contains_key(&curr_sum) {
21-
sum_to_index_mapping.insert(curr_sum, i);
22-
}
20+
sum_to_index_mapping.entry(curr_sum).or_insert(i);
2321
}
2422

25-
returnmax_length as i32;
23+
max_length as i32
2624
}
2725
}
2826

‎src/leetcode/challenge/num_unique_emails.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl Solution {
99
for email in emails {
1010
let email: Vec<_> = email.split('@').collect();
1111
let mut vhost: String = email[0].to_string().replace(".", "");
12-
if vhost.contains("+") {
12+
if vhost.contains('+') {
1313
vhost = vhost.split('+').next().unwrap().to_string();
1414
}
1515

@@ -18,7 +18,7 @@ impl Solution {
1818
set.insert(format!("{}@{}", vhost, domain));
1919
}
2020

21-
returnset.len() as i32;
21+
set.len() as i32
2222
}
2323
}
2424

‎src/leetcode/challenge/sort_array_by_parity_ii.rs

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

29-
returnans;
29+
ans
3030
}
3131
}
3232

‎src/leetcode/contest/biweekly_62.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ impl Solution2 {
2727
let mut ans = 0;
2828
for i in 0..nums.len() {
2929
for j in 0..nums.len() {
30-
if i != j {
31-
if [nums[i].clone(), nums[j].clone()].concat() == target {
32-
ans += 1;
33-
}
30+
if i != j && [nums[i].clone(), nums[j].clone()].concat() == target {
31+
ans += 1;
3432
}
3533
}
3634
}
@@ -97,8 +95,8 @@ impl Solution4 {
9795
let mut part1 = 0;
9896
let mut part2 = nums.iter().sum::<i32>();
9997
for i in 0..nums.len() {
100-
part1 = part1 + nums[i];
101-
part2 = part2 - nums[i];
98+
part1 += nums[i];
99+
part2 -= nums[i];
102100

103101
pre_calcs.push((part1, part2, i));
104102
}

‎src/leetcode/contest/weekly_261.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ impl Solution1 {
2020
while r < n {
2121
if r - l < 2 {
2222
r += 1;
23+
} else if arr[l] == 1 {
24+
arr[l] = 0;
25+
arr[l + 1] = 0;
26+
arr[l + 2] = 0;
27+
moves += 1;
2328
} else {
24-
if arr[l] == 1 {
25-
arr[l] = 0;
26-
arr[l + 1] = 0;
27-
arr[l + 2] = 0;
28-
moves += 1;
29-
} else {
30-
l += 1;
31-
}
29+
l += 1;
3230
}
3331

3432
if r == n && (arr[r - 1] == 1 || arr[r - 2] == 1 || arr[r - 3] == 1) {
@@ -44,7 +42,7 @@ impl Solution1 {
4442
// https://leetcode.com/problems/find-missing-observations/
4543
impl Solution2 {
4644
pub fn missing_rolls(rolls: Vec<i32>, mean: i32, n: i32) -> Vec<i32> {
47-
if rolls.len() == 0 || n == 0 {
45+
if rolls.is_empty() || n == 0 {
4846
return vec![];
4947
}
5048

@@ -77,7 +75,7 @@ impl Solution2 {
7775
}
7876
}
7977

80-
returnmissing_rolls;
78+
missing_rolls
8179
} else {
8280
return vec![];
8381
}

‎src/leetcode/problem/get_number_of_backlog_orders.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,18 @@ impl Solution {
6363
buy_backlog.push(o.clone());
6464
break;
6565
}
66-
} else {
67-
if !buy_backlog.is_empty() && buy_backlog.peek().unwrap().price >= o.price * -1 {
68-
let mut buy_order = buy_backlog.pop().unwrap();
69-
let amount = i32::min(buy_order.amount, o.amount);
70-
o.amount -= amount;
71-
buy_order.amount -= amount;
72-
73-
if buy_order.amount > 0 {
74-
buy_backlog.push(buy_order);
75-
}
76-
} else {
77-
sell_backlog.push(o.clone());
78-
break;
66+
} else if !buy_backlog.is_empty() && buy_backlog.peek().unwrap().price >= o.price * -1 {
67+
let mut buy_order = buy_backlog.pop().unwrap();
68+
let amount = i32::min(buy_order.amount, o.amount);
69+
o.amount -= amount;
70+
buy_order.amount -= amount;
71+
72+
if buy_order.amount > 0 {
73+
buy_backlog.push(buy_order);
7974
}
75+
} else {
76+
sell_backlog.push(o.clone());
77+
break;
8078
}
8179
}
8280
}

‎src/leetcode/top_interview/array_and_string/group_anagrams.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl Solution {
99

1010
for str in strs {
1111
let mut chars = str.chars().collect::<Vec<char>>();
12-
chars.sort();
12+
chars.sort_unstable();
1313
let key: String = chars.into_iter().collect();
1414
if let Some(v) = map.get_mut(&key) {
1515
v.push(str);
@@ -21,7 +21,7 @@ impl Solution {
2121
for (_, v) in map {
2222
ans.push(v);
2323
}
24-
returnans;
24+
ans
2525
}
2626
}
2727

‎src/leetcode/top_interview/array_and_string/increasing_triplet.rs

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

19-
returnfalse;
19+
false
2020
}
2121
}
2222

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /