Fix Clippy issues.
This commit is contained in:
parent
a688ae2cd8
commit
75b206bb24
|
@ -1,16 +1,21 @@
|
|||
pub fn first_missing_positive(mut numbers: Vec<i32>) -> i32 {
|
||||
pub fn first_missing_positive(numbers: Vec<i32>) -> i32 {
|
||||
let numbers_length = numbers.len();
|
||||
|
||||
// Mark all numbers below 1 and above the maximum range as i32::MAX.
|
||||
for index in 0..numbers_length {
|
||||
if numbers[index] < 1 || numbers[index] > numbers_length as i32 {
|
||||
numbers[index] = i32::MAX;
|
||||
}
|
||||
let mut numbers = numbers
|
||||
.into_iter()
|
||||
.map(|number| {
|
||||
if number < 1 || number > numbers_length as i32 {
|
||||
i32::MAX
|
||||
} else {
|
||||
number
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for index in 0..numbers_length {
|
||||
// For each index get its number and subtract 1.
|
||||
let index = numbers[index].abs() as usize - 1;
|
||||
let index = numbers[index].unsigned_abs() as usize - 1;
|
||||
|
||||
// If that index then isn't i32::MAX - 1 (ie. negative or above range).
|
||||
if index as i32 != i32::MAX - 1 {
|
||||
|
@ -32,5 +37,5 @@ pub fn first_missing_positive(mut numbers: Vec<i32>) -> i32 {
|
|||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| numbers_length + 1) as i32
|
||||
.unwrap_or(numbers_length + 1) as i32
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ pub fn is_number(string: String) -> bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
let mut parts = string.split("e");
|
||||
let mut parts = string.split('e');
|
||||
|
||||
let valid_significand = match parts.next() {
|
||||
Some(part) => part.parse::<f64>().is_ok(),
|
||||
|
|
|
@ -5,7 +5,7 @@ pub fn word_pattern(pattern: String, string: String) -> bool {
|
|||
let mut pattern_iter = pattern.chars();
|
||||
let mut string_iter = string.split_whitespace();
|
||||
|
||||
if pattern.len() != string_iter.clone().collect::<Vec<_>>().len() {
|
||||
if pattern.len() != string_iter.clone().count() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue