정수 배열 numbers가 매개변수로 주어집니다.
numbers의 원소 중 두 개를 곱해 만들 수 있는 최댓값
을 return하도록 solution 함수를 완성해주세요.
💡 max를 0으로 초기화 시 max의 값이 int 정수의 최대 범위인 2,147,483,647로 할당된다. 이를 해결하기 위해 초기화 시 -1을 곱하였다.
class Solution {
public int solution(int[] numbers) {
int max = Integer.MAX_VALUE*-1;
for(int i = 0; i < numbers.length; i++) {
for(int j = i+1; j < numbers.length; j++) {
if(numbers[i]*numbers[j] > max) {
max = numbers[i]*numbers[j];
}
}
}
return max;
}
}