def solution(id_list, report, k):
count = dict()
reportCount = dict()
report = list(set(report)) # ๋์ผ ์ ๊ณ ์ ๋ํ ์ค๋ณต๊ฐ ์ฒ๋ฆฌ๋ฅผ ์ํด set ๋ณํ ํ list ๋ณํ
for id in id_list: # ๋์
๋๋ฆฌ ์ด๊ธฐํ
count[id] = 0
reportCount[id] = 0
for str in report : # report์ ์ ์ฅ๋ ๊ฐ๊ฐ์ ๋ฌธ์์ด ํ์ฑํด ์ ๊ณ ํ์ ๋์
src, trg = str.split(' ')
count[trg] += 1
for str in report : #
src, trg = str.split(' ')
if count[trg] >= k :
reportCount[src] += 1
return list(reportCount.values())
- ๊ทธ๋ฆฌ๋ํ๊ฒ ๋ฌธ์ ์ ๊ทผ
- ์ฐ์
count
๋์ ๋๋ฆฌ์reportCount
๋์ ๋๋ฆฌ๋ฅผ ์ ์ธ - ๊ฐ์ ์ ๊ณ ๋ด์ฉ(= ์ ๊ณ ์๋ ๊ฐ๊ณ ์ ๊ณ ๋นํ๋ ์ฌ๋๋ ๊ฐ์)์ ์ฌ๋ฌ๋ฒ ๋์๋ 1๋ฒ์ผ๋ก๋ง ์ทจ๊ธ => ์ธ์๋ก ๋ค์ด์จ
report
์์ ์ค๋ณต์ ์ ๊ฑฐํ๊ธฐ ์ํดset
(์งํฉํํ => ์ค๋ณต์ด ์๋ค)์ผ๋ก ๋ณํ ํ ๋ค์list
๋ก ๋ณํ - for๋ฌธ์ ์ด์ฉํด dictionary๋ฅผ ์ด๊ธฐํ
- ์์ ์ด ์ ๊ณ ๋นํ ํ์ =
count
๋์ ๋๋ฆฌ์ ์ ์ฅ - ๋์ ์ ์ฌ ๋์์ด ์์ ์๊ฒ ๋ช ๊ฐ๊ฐ ์ฌ์ง =
reportCount
๋์ ๋๋ฆฌ์ ์ ์ฅ
- ์์ ์ด ์ ๊ณ ๋นํ ํ์ =
- report์ ์ ์ฅ๋ ๊ฐ๊ฐ์ ๋ฌธ์์ด์ ํ์ฑํ ๋ค ์ ๊ณ ํ์ ๋์
- ๋๊ตฐ๊ฐ์ ์ ๊ณ ํ์๊ฐ ์๊ณ๊ฐ
k
๋ฅผ ๋์ผ๋ฉดreportCount
๋์ ๋๋ฆฌ์ ๋์ - ๊ฒฐ๊ณผ ์ถ๋ ฅ
'๐ฏ CodingTest > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ (0) | 2022.04.11 |
---|---|
[Programmers] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด (0) | 2022.04.09 |
[Programmers]์ ๊ท ์์ด๋ ์ถ์ฒ (0) | 2022.04.05 |
[Programmers]๋ถ์กฑํ ๊ธ์ก ๊ณ์ฐํ๊ธฐ (0) | 2022.04.05 |
[Programmers]์ ํ๋ฒํธ ๋ชฉ๋ก - ํด์ (0) | 2022.04.05 |