1+ # https://programmers.co.kr/learn/courses/30/lessons/42862
2+
3+ def solution (n , lost , reserve ):
4+ arr = [None ] + [1 ] * n
5+
6+ for l in lost : arr [l ] -= 1
7+ for r in reserve : arr [r ] += 1
8+
9+ for i in range (1 , n + 1 ):
10+ if arr [i ] == 0 :
11+ if i - 1 != 0 and 0 <= i - 1 < n and arr [i - 1 ] > 1 :
12+ arr [i - 1 ] -= 1
13+ arr [i ] += 1
14+ elif 0 <= i + 1 <= n and arr [i + 1 ] > 1 :
15+ arr [i + 1 ] -= 1
16+ arr [i ] += 1
17+ return sum (map (lambda e : 1 if e != 0 else 0 , arr [1 :]))
18+
19+
20+ if __name__ == '__main__' :
21+ res = solution (5 , [2 , 4 ], [1 , 3 , 5 ]) # 5
22+ # res = solution(5, [2, 4], [3]) # 4
23+ # res = solution(3, [3], [1]) # 2
24+ # res = solution(10, [8, 10], [6, 7, 9]) # 10
25+ # res = solution(4, [3, 1, 2], [2, 4, 3]) # 3
26+ # res = solution(10, [5,4,3,2,1], [3,1,2,5,4]) # 10
27+ # res = solution(5, [1, 3], [2, 4]) # 5
28+ # res = solution(5, [3, 5], [2, 4]) # 5
29+ # res = solution(9, [2, 4, 7, 8], [3, 6, 9]) # 8
30+ # res = solution(5, [2, 4], [3, 5]) # 5
31+
32+ print (res )
0 commit comments