상세 컨텐츠

본문 제목

최솟값 만들기 (연습문제)

프로그래머스 코딩테스트 풀이

by 발발개발 2022. 8. 1. 16:31

본문

원본 : https://school.programmers.co.kr/learn/courses/30/lessons/12941

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

풀이

import java.util.*;

class Solution
{
    public int solution(int []A, int []B)
    {
        Arrays.sort(A);
        int answer = 0;
        int idx = A.length - 1;

        for (int num : Arrays.stream(B).sorted().toArray()) {
            answer += num * A[idx--];
        }

        return answer;
    }
}

관련글 더보기

댓글 영역