-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42862.py
More file actions
40 lines (32 loc) · 866 Bytes
/
42862.py
File metadata and controls
40 lines (32 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# https://programmers.co.kr/learn/courses/30/lessons/42862?language=python3
def solution(n, lost, reserve):
temp_lost = []
for i in lost:
try:
if reserve.index(i) >= 0:
reserve.remove(i)
continue
except:
''
temp_lost.append(i)
lost = temp_lost
answer = n - len(lost)
for i in lost:
try:
if reserve.index(i - 1) >= 0:
answer += 1
reserve.remove(i - 1)
continue
except:
''
try:
if reserve.index(i + 1) >= 0:
answer += 1
reserve.remove(i + 1)
continue
except:
''
return answer
print(solution(5, [2, 4], [1, 3, 5]))
print(solution(5, [2, 4], [3]))
print(solution(3, [1, 2], [2, 3]))