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();
|
let numbers_length = numbers.len();
|
||||||
|
|
||||||
// Mark all numbers below 1 and above the maximum range as i32::MAX.
|
// Mark all numbers below 1 and above the maximum range as i32::MAX.
|
||||||
for index in 0..numbers_length {
|
let mut numbers = numbers
|
||||||
if numbers[index] < 1 || numbers[index] > numbers_length as i32 {
|
.into_iter()
|
||||||
numbers[index] = i32::MAX;
|
.map(|number| {
|
||||||
}
|
if number < 1 || number > numbers_length as i32 {
|
||||||
|
i32::MAX
|
||||||
|
} else {
|
||||||
|
number
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
for index in 0..numbers_length {
|
for index in 0..numbers_length {
|
||||||
// For each index get its number and subtract 1.
|
// 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 that index then isn't i32::MAX - 1 (ie. negative or above range).
|
||||||
if index as i32 != i32::MAX - 1 {
|
if index as i32 != i32::MAX - 1 {
|
||||||
|
@ -32,5 +37,5 @@ pub fn first_missing_positive(mut numbers: Vec<i32>) -> i32 {
|
||||||
None
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut parts = string.split("e");
|
let mut parts = string.split('e');
|
||||||
|
|
||||||
let valid_significand = match parts.next() {
|
let valid_significand = match parts.next() {
|
||||||
Some(part) => part.parse::<f64>().is_ok(),
|
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 pattern_iter = pattern.chars();
|
||||||
let mut string_iter = string.split_whitespace();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue