https://programmers.co.kr/learn/courses/30/lessons/42862
Code
1
2
3
4
5
6
7
8
9
10
11
def solution(n, lost, reserve):
_reserve = [r for r in reserve if r not in lost]
_lost = [l for l in lost if l not in reserve]
for r in _reserve:
f = r - 1
b = r + 1
if f in _lost:
_lost.remove(f)
elif b in _lost:
_lost.remove(b)
return n - len(_lost)
Complexity
$O(n+m)$
- $n$ = len(lost)
- $m$ = len(reserve)
PREVIOUSEtc