[프로그래머스] 12941 최솟값 만들기 / Java 정답

programmers

쉬운 문제라도 문제를 푸는 방법은 다양합니다.

더 명확하고 깔끔한 문제 해결 방법을 아신다면 자유롭게 말씀해주세요.

프로그래머스 12941 최솟값 만들기

프로그래머스 저작권을 침해하지 않기 위해

문제 보시고 싶으시면 버튼을 눌러주세요.

답변 형식
프로그래머스 12941 자바
프로그래머스 12941 파이썬

배열 A, B 원소를 1번 씩만 사용하여 총 합 answer이 최소가 되는 곱셈 결과를 찾으면 된다.

풀이 조건

결과값이 최소가 되기 위해서 각각의 곱셈 값이 최소가 되어야 했다.

A의 최대와 B의 최소 / A의 최소와 B의 최대를 계산해야 했다.

import java.util.Arrays;

class Solution
{
    public int solution(int[] A, int[] B)
    {
        Arrays.sort(A);
        Arrays.sort(B);
        /// A, B 각각 sort하여 오름차순 정렬

        int answer = 0;
       
        int q = B.length–1;
   
        for(int i=0; i<A.length; i++){
            answer += A[i]*B[q–];
            /// A배열을 작은 수부터 큰 수 순서로
            /// B배열을 큰 수부터 작은 수 순서로
            /// 곱해서 return 값에 더 함
        }
        return answer;
    }
}
import java.util.Arrays;

class Solution
{
    public int solution(int[] A, int[] B)
    {
        Arrays.sort(A);
        Arrays.sort(B);
       
        int answer = 0;
       
        int q = B.length–1;
       
        for(int i=0; i<A.length; i++){
            answer += A[i]*B[q–];
        }
        return answer;
    }
}

“[프로그래머스] 12941 최솟값 만들기 / Java 정답”의 88개의 댓글

  1. [2312]ff777 Official Login | Best GCash Online Casino in Philippines,ff777 offers a seamless app download for the top online slot games in the Philippines. Enjoy secure GCash transactions and learn how to play baccarat. Join now! visit: ff777

  2. Picking up lottery tickets used to be such a hassle until I discovered this app. The drawing results update instantly and the payout process is lightning fast. I love how easy it is to set up quick picks and track my numbers all in one place. Definitely my new go to for daily draws. Visit the official app 66lotteryapp

  3. I have tried quite a few betting sites over the years but this one really nailed the user experience from day one. Logging in is quick and the mobile version runs perfectly on my phone. Just hit a pretty sweet combo on a classic fruit slot last night and loved how smooth the payout went. If you want a spot that feels trustworthy and actually treats its players well, this is it. x7betlogin

  4. [4832]Spinbara লগইন এবং অ্যাপ ডাউনলোড | বিকাশ ক্যাসিনো গেম,spinbara login করুন এবং অ্যাপ ডাউনলোড করে লাইভ ক্যাসিনো বোনাস অফার উপভোগ করুন। বিকাশ দিয়ে ক্যাসিনো গেম খেলে জিতে নিন দারুণ সব পুরস্কার। visit: spinbara

  5. [3504]1991bet Official Login | বিকাশ পেমেন্ট ও সেরা ক্যাসিনো বোনাস,1991bet অ্যাপ ডাউনলোড করে উপভোগ করুন সেরা স্লট গেম ও আকর্ষণীয় ক্যাসিনো বোনাস। বিকাশ দিয়ে সহজে লেনদেন করে আজই আপনার অ্যাকাউন্ট খুলুন। visit: 1991bet

  6. [7076]Melate Casino: Registro, Bono y App APK para Tragamonedas Online,Únete a Melate Casino y vive la emoción de las mejores tragamonedas online en México. Regístrate hoy, aprovecha nuestro bono de bienvenida y descarga la App APK para jugar desde cualquier lugar. ¡Tu gran premio te espera! visit: melate

  7. [9694]abcvip | Link vào tải app và sảnh quay hũ đổi thưởng,Truy cập abcvip để trải nghiệm game quay hũ đổi thưởng hấp dẫn, tìm hiểu cách chơi baccarat online và nạp tiền casino qua momo nhanh chóng. Tham gia ngay! visit: abcvip

댓글 달기

이메일 주소는 공개되지 않습니다.