视频讲解:
https://www.bilibili.com/video/BV1Le4y1R7xu?t=1289.1
// 模版
n := len(nums)
fa := make([]int, n+1)
for i := range fa {
fa[i] = i
}
var find func(int) int
find = func(x int) int {
if fa[x] != x {
fa[x] = find(fa[x])
}
return fa[x]
}
视频讲解:
https://www.bilibili.com/video/BV1Le4y1R7xu?t=1289.1
// 模版
n := len(nums)
fa := make([]int, n+1)
for i := range fa {
fa[i] = i
}
var find func(int) int
find = func(x int) int {
if fa[x] != x {
fa[x] = find(fa[x])
}
return fa[x]
}