혼자 놀기의 달인 ( Level 2, Python, 연습문제 )
def dfs(cards, cur, visited, count): if not visited[cur]: visited[cur] = count return dfs(cards, cards[cur] - 1, visited, count) return def solution(cards): visited = [0] * len(cards) count = 1 for c in cards: if not visited[c - 1]: dfs(cards, c - 1, visited, count) count += 1 check = {} for v in visited: check[v] = check.get(v, 0) + 1 ans = sorted(list(check.values()), reverse=True) return ans[..