Skip to content

Commit fc5c181

Browse files
committed
Refactor
1 parent 3b5b9ea commit fc5c181

File tree

65 files changed

+75
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+75
-79
lines changed

src/problem_0330_patching_array/greedy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl Solution {
1010
let mut iter = nums.into_iter();
1111

1212
while max <= n {
13-
if let Some(num) = iter.next().map(|x| x as u32) {
13+
if let Some(num) = iter.next().map(i32::cast_unsigned) {
1414
while num > max {
1515
max *= 2;
1616
result += 1;

src/problem_0372_super_pow/iterative.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ impl Solution {
2323
let a = a as u32 % M;
2424
let mut result = 1;
2525

26-
for digit in b.into_iter().map(|d| d as _) {
27-
result = (Self::pow_mod(result, 10, M) * Self::pow_mod(a, digit, M)) % M;
26+
for digit in b {
27+
result = (Self::pow_mod(result, 10, M) * Self::pow_mod(a, digit.cast_unsigned(), M)) % M;
2828
}
2929

3030
result as _

src/problem_0372_super_pow/iterative_2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ impl Solution {
2424
let a = a as u32 % M;
2525
let mut result = 1;
2626

27-
for digit in b.into_iter().map(|d| d as _) {
28-
result = (Self::pow_mod(result, 10, M) * Self::pow_mod(a, digit, M)) % M;
27+
for digit in b {
28+
result = (Self::pow_mod(result, 10, M) * Self::pow_mod(a, digit.cast_unsigned(), M)) % M;
2929
}
3030

3131
result as _

src/problem_0911_online_election/precompute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct TopVotedCandidate {
77
impl TopVotedCandidate {
88
fn new(persons: Vec<i32>, times: Vec<i32>) -> Self {
99
let n = persons.len();
10-
let mut iter = times.into_iter().map(|time| time as u32).zip(persons);
10+
let mut iter = times.into_iter().map(i32::cast_unsigned).zip(persons);
1111
let mut leads = Vec::with_capacity(n);
1212
let mut counts = vec![0_u32; n];
1313
let (first_time, first_person) = iter.next().unwrap();

src/problem_1223_dice_roll_simulation/dynamic_programming.rs

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

1818
pub fn die_simulator(n: i32, roll_max: Vec<i32>) -> i32 {
1919
let n = n as usize;
20-
let roll_max = <[_; 6]>::try_from(roll_max).ok().unwrap().map(|value| value as u32);
20+
let roll_max = <[_; 6]>::try_from(roll_max).ok().unwrap().map(i32::cast_unsigned);
2121
let mut cache = vec![([0_u32; 6], 1_u32); n + 1];
2222
let mut prev = &cache[0];
2323

src/problem_1250_check_if_it_is_a_good_array/iterative.rs

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

1717
pub fn is_good_array(nums: Vec<i32>) -> bool {
18-
let mut iter = nums.into_iter().map(|num| num as u32);
18+
let mut iter = nums.into_iter().map(i32::cast_unsigned);
1919
let mut gcd = iter.next().unwrap();
2020

2121
for num in iter {

src/problem_1262_greatest_sum_divisible_by_three/dynamic_programming_2.rs

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

55
impl Solution {
66
pub fn max_sum_div_three(nums: Vec<i32>) -> i32 {
7-
let mut iter = nums.into_iter().map(|num| num as u32);
7+
let mut iter = nums.into_iter().map(i32::cast_unsigned);
88
let mut max_0 = 0;
99

1010
let (mut max_1, mut max_2) = 'outer: loop {

src/problem_1262_greatest_sum_divisible_by_three/dynamic_programming_3.rs

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

55
impl Solution {
66
pub fn max_sum_div_three(nums: Vec<i32>) -> i32 {
7-
let mut iter = nums.into_iter().map(|num| num as u32);
7+
let mut iter = nums.into_iter().map(i32::cast_unsigned);
88
let mut max_0 = 0;
99
let mut max_1;
1010
let mut max_2;

src/problem_1262_greatest_sum_divisible_by_three/dynamic_programming_4.rs

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

55
impl Solution {
66
pub fn max_sum_div_three(nums: Vec<i32>) -> i32 {
7-
let mut iter = nums.into_iter().map(|num| num as u32);
7+
let mut iter = nums.into_iter().map(i32::cast_unsigned);
88
let mut cache = (0, 0, 0);
99

1010
'outer: loop {

src/problem_1354_construct_target_array_with_multiple_sums/restore_original_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::num::NonZeroU32;
88
impl Solution {
99
pub fn is_possible(target: Vec<i32>) -> bool {
1010
let mut sum = target.iter().copied().sum::<i32>() as u32;
11-
let mut queue = target.into_iter().map(|value| value as u32).collect::<BinaryHeap<_>>();
11+
let mut queue = target.into_iter().map(i32::cast_unsigned).collect::<BinaryHeap<_>>();
1212

1313
loop {
1414
let mut top = queue.peek_mut().unwrap();

0 commit comments

Comments
 (0)