유형 : 구현 (그리디?)

풀이 시간 : 10분

 

1. 나의 풀이

def solution(A,B):
    answer = 0
    A.sort()
    B.sort(reverse = True)
    
    res = []
    for i in range(len(A)):
        res.append(A[i] * B[i])
    return sum(res)

 

2, map을 사용한 풀이

def solution(A,B):    
    return sum(map(lambda a, b : a*b, sorted(A), sorted(B, reverse = True)))

 

map (함수, iterable)

 

3. zip을 이용한 풀이

두 개의 list를 묶을 때 zip을 사용할 수 있다. 

def solution(A,B):    
    return sum([a * b for a, b in zip(sorted(A), sorted(B, reverse = True))])
복사했습니다!