20250402 finished.
This commit is contained in:
parent
cf2fec91aa
commit
02d7c72ac1
|
@ -574,3 +574,5 @@ mod p2109_adding_spaces_to_a_string;
|
|||
mod p2278_percentage_of_letter_in_string;
|
||||
|
||||
mod p2140_solving_questions_with_brainpower;
|
||||
|
||||
mod p2873_maximum_value_of_an_ordered_triplet_i;
|
||||
|
|
39
src/problem/p2873_maximum_value_of_an_ordered_triplet_i.rs
Normal file
39
src/problem/p2873_maximum_value_of_an_ordered_triplet_i.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* [2873] Maximum Value of an Ordered Triplet I
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn maximum_triplet_value(nums: Vec<i32>) -> i64 {
|
||||
let nums: Vec<i64> = nums.into_iter().map(|x| x as i64).collect();
|
||||
|
||||
let mut result = 0;
|
||||
let n = nums.len();
|
||||
|
||||
for i in 0..n {
|
||||
for j in i + 1..n {
|
||||
for k in j + 1..n {
|
||||
result = result.max((nums[i] - nums[j]) * nums[k])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_2873() {
|
||||
assert_eq!(77, Solution::maximum_triplet_value(vec![12, 6, 1, 2, 7]));
|
||||
assert_eq!(133, Solution::maximum_triplet_value(vec![1, 10, 3, 4, 19]));
|
||||
assert_eq!(0, Solution::maximum_triplet_value(vec![1, 2, 3]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user