题解 | #三个数的最大乘积#
三个数的最大乘积
https://www.nowcoder.com/practice/8ae05c2913fe438b8b14f3968f64fc0b
using System;
using System.Collections.Generic;
class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 最大乘积
* @param A int整型一维数组
* @return long长整型
*/
public long solve (List<int> A) {
// write code here
if (A == null)
return 0;
if (A.Count < 3)
return 0;
A.Sort();
int nLen = A.Count;
long nMaxF = (long)A[nLen - 1] * (long)A[nLen - 2] * (long)A[nLen - 3];
long nMaxS = (long)A[0] * (long)A[1] * (long)A[nLen - 1];
return nMaxF > nMaxS ? nMaxF : nMaxS;
}
}