-
2024 KAKAO WINTER INTERNSHIP 도넛과 막대 그래프코딩 테스트/Level 2 2024. 8. 9. 22:37반응형
https://school.programmers.co.kr/learn/courses/30/lessons/258711
def solution(edges): answer = [0, 0, 0, 0] counter = {} for a, b in edges: counter.setdefault(a, [0, 0]) counter.setdefault(b, [0, 0]) counter[a][0] += 1 counter[b][1] += 1 for vertex, counts in counter.items(): if counts[0] >= 2 and counts[1] == 0: answer[0] = vertex elif counts[0] == 0 and counts[1] > 0: answer[2] += 1 elif counts[0] >= 2 and counts[1] >= 2: answer[3] += 1 answer[1] = counter[answer[0]][0] - answer[2] - answer[3] return answer
반응형