24 lines
546 B
Java
24 lines
546 B
Java
package LanQiaoOJ;
|
||
|
||
import java.util.Arrays;
|
||
import java.util.Scanner;
|
||
|
||
public class 寻找三个数的最大乘积2 {
|
||
static int N=1010;
|
||
static int []a=new int [N];
|
||
|
||
public static void main(String[] args) {
|
||
Scanner sc=new Scanner(System.in);
|
||
int n=sc.nextInt();
|
||
for(int i=0;i<n;i++) {
|
||
a[i]=sc.nextInt();
|
||
|
||
//如果都是整数——贪心算法——选出最大三个
|
||
Arrays.sort(a,0,n);//数组排序算法————时间复杂度:nlogn
|
||
int ans=a[n-1]*a[n-2]*a[n-3];
|
||
ans=Math.max(ans, a[0]*a[1]*a[n-1]);
|
||
System.out.print(ans);
|
||
}
|
||
}
|
||
}
|