Created
October 10, 2021 16:07
-
-
Save Israel-Miles/31ea1fa8147ecdca2ae71dfd0429fb64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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