삽집하는 개발들/알고리즘

[18일차][프로그래머스][42862]체육복

악투 2023. 7. 6. 22:13
반응형
def solution(n, lost, reserve):
    reserve_arr = sorted([ data for data in reserve if data not in lost ])
    lost_arr = sorted([ data for data in lost if data not in reserve ])
    result = n
    
    if len(lost_arr) > 0 or len(reserve_arr) > 0:
        for data in reserve_arr:
            if data - 1 in lost_arr:
                lost_arr.remove(data-1)
                continue

            if data + 1 in lost_arr:
                lost_arr.remove(data+1)
                continue
    
    result = result - len(lost_arr)
        
    return result
반응형