기억은 짧고 기록은 길다
[프로그래머스/Programmers] 최솟값 만들기 - Python 본문
Link
코딩테스트 연습 - 최솟값 만들기
길이가 같은 배열 A, B 두개가 있습니다. 각 배열은 자연수로 이루어져 있습니다. 배열 A, B에서 각각 한 개의 숫자를 뽑아 두 수를 곱합니다. 이러한 과정을 배열의 길이만큼 반복하며, 두 수를 곱
programmers.co.kr
Solution
def solution(A, B):
answer = 0
for i, j in zip(sorted(A), sorted(B, reverse=True)):
answer += i * j
return answer
🔑 key point: sorted(A), sorted(B, reverse=True)
📌 Tip: zip()
Other Solution
def solution(A, B):
return sum(a * b for a, b in zip(sorted(A), sorted(B, reverse = True)))
🔑 key point: sorted(A), sorted(B, reverse=True)
📌 Tip: zip()'CodingTest > programmers' 카테고리의 다른 글
| [프로그래머스/Programmers] 타겟 넘버 - Python (0) | 2021.09.23 |
|---|---|
| [프로그래머스/Programmers] 튜플 - Python (0) | 2021.09.22 |
| [프로그래머스/Programmers] 최댓값과 최솟값 - Python (0) | 2021.09.22 |
| [프로그래머스/Programmers] 짝지어 제거하기 - Python (0) | 2021.09.21 |
| [프로그래머스/Programmers] 주식가격 - Python (0) | 2021.09.21 |
Comments