Skip to content

Instantly share code, notes, and snippets.

@Israel-Miles
Created October 10, 2021 16:07
Show Gist options
  • Save Israel-Miles/31ea1fa8147ecdca2ae71dfd0429fb64 to your computer and use it in GitHub Desktop.
Save Israel-Miles/31ea1fa8147ecdca2ae71dfd0429fb64 to your computer and use it in GitHub Desktop.
func (uf *UnionFind) find(x int) int {
return uf.root[x]
}
func (uf *UnionFind) union(x, y int) {
rootX := uf.find(x)
rootY := uf.find(y)
if rootX != rootY {
for i := range uf.root {
if uf.root[i] == rootY {
uf.root[i] = rootX
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment