20250219 finished.
This commit is contained in:
parent
a4601fef46
commit
7185e09266
|
@ -492,3 +492,5 @@ mod p1706_where_will_the_ball_fall;
|
||||||
mod p1299_replace_elements_with_greatest_element_on_right_side;
|
mod p1299_replace_elements_with_greatest_element_on_right_side;
|
||||||
|
|
||||||
mod p2080_range_frequency_queries;
|
mod p2080_range_frequency_queries;
|
||||||
|
|
||||||
|
mod p624_maximum_distance_in_arrays;
|
||||||
|
|
43
src/problem/p624_maximum_distance_in_arrays.rs
Normal file
43
src/problem/p624_maximum_distance_in_arrays.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
use std::thread::available_parallelism;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [624] Maximum Distance in Arrays
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn max_distance(arrays: Vec<Vec<i32>>) -> i32 {
|
||||||
|
let mut result = 0;
|
||||||
|
// -10e4 <= array[i][j] <= 10e4
|
||||||
|
let (mut min, mut max) = (10_000 + 1, -10_000 - 1);
|
||||||
|
|
||||||
|
for array in arrays {
|
||||||
|
result = result
|
||||||
|
.max(*array.last().unwrap() - min)
|
||||||
|
.max(max - *array.first().unwrap());
|
||||||
|
|
||||||
|
min = min.min(*array.first().unwrap());
|
||||||
|
max = max.max(*array.last().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_624() {
|
||||||
|
assert_eq!(
|
||||||
|
4,
|
||||||
|
Solution::max_distance(vec![vec![1, 2, 3], vec![4, 5], vec![1, 2, 3]])
|
||||||
|
);
|
||||||
|
assert_eq!(0, Solution::max_distance(vec![vec![1], vec![1]]));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user