프로그래머스 (최대값만들기 (1)

수민·2022년 10월 22일
0

알고리즘

목록 보기
1/22
post-thumbnail

😃

  • 문제설명
    😃정수 배열 numbers가 매개변수로 주어집니다. numbers의 원소 중 두 개를 곱해 만들 수 있는 최댓값을 return하도록 solution 함수를 완성해주세요.
  • 제한사항

0 ≤ numbers의 원소 ≤ 10,000

2 ≤ numbers의 길이 ≤ 100

-[ ] 입출력 예!

예제1

function solution(numbers) {

let answer=[];
for(let i=0; i<numbers.length; i++){
for(let j=0; j<numbers.length; j++){
if(i!==j){
answer.push(numbers[i]*numbers[j])
}
}
}

return Math.max(...answer)

}

예제2

function solution(numbers) {

const[first,second,...three]=number.sort((a,b)=>b-a);

return first*second;
}

  • 코드 작성
  • 똑바로 하기!
  • 성실히!
profile
헬창목표

0개의 댓글