题解 | #最大乘积#
最大乘积
http://www.nowcoder.com/practice/5f29c72b1ae14d92b9c3fa03a037ac5f
public static void main(String[] args) {
PDD1();
}
public static void PDD1(){
long sum = 1;
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
List<Long> arrayList = new ArrayList<>();
for (int i = 0; i < n; i++) {
arrayList.add(scanner.nextLong());
}
arrayList.sort((o1, o2) -> {
Long tmp = o2-o1;
return tmp.intValue();
}
);
if (arrayList.get(1)*arrayList.get(2)<arrayList.get(arrayList.size()-1)*arrayList.get(arrayList.size()-2)){
sum = arrayList.get(0)*arrayList.get(arrayList.size()-1)*arrayList.get(arrayList.size()-2);
}else {
sum = arrayList.get(0)*arrayList.get(1)*arrayList.get(2);
}
System.out.println(sum);
}