https://school.programmers.co.kr/learn/courses/30/lessons/42576
def solution(participant, completion):
d = dict()
for person in participant:
if person not in d:
d[person] = 1
else:
d[person] += 1
for c in completion:
if c in d:
d[c] -= 1
for person in d.keys():
if d.get(person) == 1:
return person
μ λ¬Έμ λ ν΄μλ₯Ό μ¬μ©νμ¬ νλΌκ³ μλ €μ£Όλ λ¬Έμ μλ€.
μ λ¬Έμ λ ν΄μλ₯Ό μ¬μ©νμ§ μκ³ λ μ½κ² ꡬνμ΄ κ°λ₯νμ§λ§,
ν¨μ¨μ±μμ ν΅κ³Όλμ§ μμμ λμ
λ리 ꡬ쑰λ₯Ό μ¬μ©ν΄λ³΄κΈ°λ‘ νλ€.
νμ΄μ¬μμ ν΄μλ₯Ό ꡬννκΈ° μν΄μλ νμ΄μ¬μ λμ λ리λ₯Ό μ¬μ©νλ©΄ λλ€.
- 리μ€νΈλ₯Ό μΈ μ μμ λ
-> λ¬Έμ μΈλ±μ€μ²λΌ μ¬μ©νκ³ μΆμ κ²½μ°- λΉ λ₯Έ μ κ·Ό / νμμ΄ νμν λ
-> λμ λ리 ν¨μμ μκ°λ³΅μ‘λλ λλΆλΆ O(1)λ‘ λ§€μ° λΉ λ¦- μ§κ³κ° νμν λ
-> countλ©μλλ₯Ό μ¬μ©, μμμ κ°μλ₯Ό μΈλ λ¬Έμ μμ μ 리
dict = {'park':1,'kim':2,'Baek':3}
print(dict.keys()) # dict_keys(['park', 'kim', 'Baek'])
print(dict.values()) # dict_values([1, 2, 3])
print(dict.get('park')) # 1
dict.keys
() - λμ
λ리μ ν€λ€μ λ°ν
dict.values
() - λμ
λ리μ ν€μ κ°λ€μ λ°ν
dict.get
(μ°Ύκ³ μνλ ν€) - ν΄λΉ ν€μ κ°μ λ°ν
μ°Έκ³ νλ©΄ μ’μ λΈλ‘κ·Έ!
https://yunaaaas.tistory.com/46