LeetCode/NeetCode 98

Graphs (Union Find): 684. Redundant Connection

684. Redundant Connection https://youtu.be/1lNK80tOTfc  https://youtu.be/FXWRE67PLL0?si=09q1EDMfBhbMNpJk class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: # Union-Find 알고리즘으로 사이클을 형성하는 간선을 찾는 함수 # Use Union-Find algorithm to find the edge that creates a cycle. n = len(edges) # 간선의 개수 (Number of edges) # 부모 노드를 저장하는 배열 ..

LeetCode/NeetCode 2025.01.28

[LinkedLists: Fast and Slow Pointers] Linked List Cycle II ★★★★★

142. Linked List Cycle II 이 문제는 Linked List Cycle Detection 문제 중 하나로,**Floyd's Cycle Detection Algorithm (Tortoise and Hare)**를 활용하여 해결할 수 있습니다.아래는 단계별 풀이 방법입니다.1. Floyd’s Cycle Detection Algorithm (토끼와 거북이)두 포인터(Tortoise와 Hare)를 사용하여 Linked List를 순회합니다.속도 차이를 이용해 두 포인터가 같은 노드에 도달하면 사이클이 있음을 확인할 수 있습니다.사이클이 발견되면, 사이클의 시작 노드를 찾는 추가 작업을 수행합니다.2. 단계별 풀이1단계: 사이클 존재 여부 확인slow 포인터는 한 번에 한 노드씩 이동합니다.fa..

LeetCode/NeetCode 2025.01.27