알고리즘 풀이/Codility

codility - MaxProductOfThree (Sorting)

배게 2019. 12. 13. 03:36
728x90

+++큰 순으로 3개


--작은순으로 2개 & +큰순으로 1개


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    public int solution(int[] A) {
        // write your code in Java SE 8
        
        Arrays.sort(A);
        
        int leng = A.length;
        
        // for(int a : A ) System.out.println(a);
        int mmp = A[0]*A[1]*A[leng-1];
        int ppp = A[leng-1]*A[leng-2]*A[leng-3];
        
        return (mmp>ppp)?mmp:ppp;
        
        
        
        
    }
cs


댓글수0