Catalogue
                    
                
            
            DP
Matrix Path
from (0, 0) to (0, n-1), traverse to right, right bottom and right top!
- Follow Up1 : Must go through some points
 - Follow Up2 : Must go through a certain height
 
Graph -> Tree
Redundant Connection
684. Redundant Connection
Undirected Graph!
- Union Find
 
- when the inputs are edges, you do not need to construct the graph
 - path compression, but how about the balanced part?
 
- DFS
 
1  | class Solution(object):  | 
685. Redundant Connection II
Directed Graph
- Case1: There is a loop in the graph, and no vertex has more than 1 parent.
 
- => Union Find
 
- Case2: A vertex has more than 1 parent, but there isn’t a loop in the graph.
 
- => last node (indegree > 1)
 
- Case3: A vertex has more than 1 parent, and is part of a loop.
 
- Delete the second edge!
 
1  | class Solution(object):  | 
Other
843. Guess the Word
1  | class Solution:  | 
DFS
Remove Marble
1  | def dfs(board, x, y, row_visited, col_visited):  |