본문 바로가기

Coding Test/프로그래머스

[프로그래머스/자바] 최댓값 만들기 (2)

import java.util.Arrays;

class Solution {
    public int solution(int[] numbers) {
        Arrays.sort(numbers);
        int length = numbers.length;
        int a = numbers[0] * numbers[1];
        int b = numbers[length - 1] * numbers[length - 2];
        return a > b ? a : b;
    }
}

import java.util.Arrays;

class Solution {
    public int solution(int[] numbers) {
        Arrays.sort(numbers);
        int length = numbers.length;
        return Math.max(numbers[0] * numbers[1], numbers[length - 1] * numbers[length - 2])
    }
}