hye-log

[프로그래머스]최솟값 만들기(Python) 본문

CodingTest/Programmers

[프로그래머스]최솟값 만들기(Python)

iihye_ 2022. 9. 16. 11:35

0. 문제 링크

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

 

프로그래머스

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

programmers.co.kr

 

1. 문제 설명

1) 두 배열에서 중복되지 않게 선택해서 곱한 수의

2) 최소값 구하기

 

2. 입출력

# input
A = [1,4,2]
B = [5,4,4]

# output
result = 29

 

3. 코드

def solution(A,B):
    answer = 0

    A = sorted(A)                   # A 오름차순 정렬
    B = sorted(B, reverse=True)     # B 내림차순 정렬

    for i in range(len(A)):
        answer += A[i] * B[i]       # 순서대로 곱하기

    return answer

 

실행 결과

 

4. 알게된 점

1) 최소값을 찾기 위해서 각 배열의 정렬을 활용

 

5. Github

https://github.com/iihye/Algorithm/blob/main/Programmers/make_min.py

 

GitHub - iihye/Algorithm

Contribute to iihye/Algorithm development by creating an account on GitHub.

github.com

 

728x90
Comments