정수 배열 numbers
가 매개변수로 주어집니다. numbers
의 원소 중 두 개를 곱해 만들 수 있는 최댓값을 return하도록 solution 함수를 완성해주세요.
numbers
의 원소 ≤ 10,000numbers
의 길이 ≤ 100numbers | result |
---|---|
[1, 2, -3, 4, -5] | 15 |
[0, -31, 24, 10, 1, 9] | 240 |
[10, 20, 30, 5, 5, 20, 5] | 600 |
입출력 예 #1
입출력 예 #2
입출력 예 #3
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public int solution(int[] numbers) {
List<int> list = new List<int>();
for(int i = 0; i < numbers.Length; i++)
{
for(int j = 0; j < numbers.Length; j++)
{
if(i == j)
{
continue;
}
else
{
list.Add(numbers[i] * numbers[j]);
}
}
}
return list.Max();
}
}
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges