题解 | #三个数的最大乘积# | Rust
三个数的最大乘积
https://www.nowcoder.com/practice/8ae05c2913fe438b8b14f3968f64fc0b
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 最大乘积 * @param A int整型一维数组 * @return long长整型 */ pub fn solve(&self, A: Vec<i32>) -> i64 { let mut A = A; A.sort_by(|a, b| b.cmp(a)); let n = A.len(); return A[0] as i64 * std::cmp::max((A[1] * A[2]) as i64, (A[n-1] * A[n-2]) as i64); } }