리트코드 684 파이썬1 [LeetCode] 684. Redundant Connection (파이썬/python) 🎈문제 https://leetcode.com/problems/redundant-connection/ 🎁어떤 알고리즘? 1. union-find 알고리즘 (생각했던 코드가 동작하지 않아 검색 후 알게 된 알고리즘) -> 각각의 idx를 노드라고 설정했을 때, 연결된 가장 작은 숫자의 노드를 idx의 값으로 가지는 방식으로 연결된 그래프를 찾는 방식이다. 💻코드 class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: # 방문 표시와 부모 노드를 동시에 기록할 리스트 par = [0] * (len(edges)+1) def find(x): if par[x] == 0: # 처음 방문 return x return .. 2023. 8. 10. 이전 1 다음