https://programmers.co.kr/learn/courses/30/lessons/42576
Code
1. Counter
1
2
3
4
5
6
7
8
from collections import Counter
def solution(participant, completion):
p = Counter(participant)
c = Counter(completion)
p = p - c
answer = list(p.keys())[0]
return answer
2. Hash
1
2
3
4
5
6
7
8
9
10
11
def solution(participant, completion):
answer = ''
temp = 0
dic = {}
for part in participant:
dic[hash(part)] = part
temp += int(hash(part))
for com in completion:
temp -= hash(com)
answer = dic[temp]
return answer
Complexity
$O(n)$
- $n$ = len(participant)
- $m$ = len(completion)
- $n \leq$ 0.1M
- $m$ <= $n$ - 1
PREVIOUSEtc