https://programmers.co.kr/learn/courses/30/lessons/42862
def solution(n, lost, reserve):
answer = []
#์ฒด์ก๋ณต์ ์์ด๋ฒ๋ฆฐ ํ์ ์ค ์ฌ๋ฒ์ด ์๋ ํ์ =์ฐธ๊ฐ๋ถ๊ฐ
set_lost = set(lost)-set(reserve)
#์ฒด์ก๋ณต ์ฌ๋ฒ์ด ์๋ ํ์ ์ค ์์ด๋ฒ๋ฆฐ ํ์๋นผ๊ณ =๋น๋ ค์ค์์๋ ํ์
set_reserve = set(reserve)-set(lost)
#์ฐธ๊ฐ ๊ฐ๋ฅํ ํ์ ์ค
for i in set_reserve:# ๊ทธ ์ผ์ชฝ์ด ์ฒด์ก๋ณต์ด ์๋ ๊ฒฝ์ฐ
if i-1 in set_lost:
set_lost.remove(i-1)
elif i+1 in set_lost: #๊ทธ ์ค๋ฅธ์ชฝ์ด ์๋ ๊ฒฝ์ฐ
set_lost.remove(i+1)
answer = n-len(set_lost)
return answer
'Algorithm > ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ํํ - Python (0) | 2021.05.18 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ด ๋๋ง์๊ธฐ - Python (0) | 2021.05.18 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฉ๋ด๋ฆฌ๋ด์ผ - Python (0) | 2021.05.18 |
[ํ๋ก๊ทธ๋๋จธ์ค] ํฌ์ผ๋ชฌ - Python (0) | 2021.05.18 |
[ํ๋ก๊ทธ๋๋จธ์ค] 2016 - Python (0) | 2019.08.13 |