struct Solution{
}
impl Solution {
fn new() -> Self {
Solution{}
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 最大乘积
* @param A int整型一维数组
* @return long长整型
*/
pub fn solve(&self, A: Vec<i32>) -> i64 {
let mut vec = A;
vec.sort();
fn contain_minus(vec: Vec<i32>) -> bool {
let mut re = false;
for i in vec {
if i < 0 {
re = true;
}
}
re
}
if contain_minus(vec.clone()) {
if vec[0] as i64 * vec[1] as i64 > vec[vec.len() - 2] as i64 * vec[vec.len() - 3] as i64 {
return vec[vec.len() - 1] as i64 * vec[0] as i64 * vec[1] as i64;
}
}
return vec[vec.len() - 1] as i64 * vec[vec.len() - 2] as i64 * vec[vec.len() - 3] as i64;
}
}