https://programmers.co.kr/learn/courses/30/lessons/42576
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ์์ฃผํ์ง ๋ชปํ ์ ์
์๋ง์ ๋ง๋ผํค ์ ์๋ค์ด ๋ง๋ผํค์ ์ฐธ์ฌํ์์ต๋๋ค. ๋จ ํ ๋ช ์ ์ ์๋ฅผ ์ ์ธํ๊ณ ๋ ๋ชจ๋ ์ ์๊ฐ ๋ง๋ผํค์ ์์ฃผํ์์ต๋๋ค. ๋ง๋ผํค์ ์ฐธ์ฌํ ์ ์๋ค์ ์ด๋ฆ์ด ๋ด๊ธด ๋ฐฐ์ด participant์ ์์ฃผํ ์ ์
programmers.co.kr
ํ์ด
# # ํ๋ก๊ทธ๋๋จธ์ค 1๋จ๊ณ - ์์ฃผํ์ง ๋ชปํ ์ ์
def solution(participant, completion):
participant.sort()
completion.sort()
for p, c in zip(participant, completion):
if p != c: # ์ ๋ ฌ ํ์ ๋ participant์ completion์ด ๋ค๋ฅผ ๊ฒฝ์ฐ
return p
return participant.pop()
import collections
def solution(participant, completion):
answer = collections.Counter(participant) - collections.Counter(completion)
return list(answer.keys())[0]
collections ์ Counter ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฃฐ ํด๊ฒฐ์ด ๊ฐ๋ฅํ์๋ค.