Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
修改 union find
Browse files Browse the repository at this point in the history
  • Loading branch information
aQuaYi committed Sep 28, 2019
1 parent 9ead335 commit 714aefb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions routine/union-find/union-find.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ package unionfind

// leetcode 中需要 union 的集合都太小了,最普通的集合算法,就够用了

type union struct {
type unionFind struct {
parent []int
}

func newUnion(size int) *union {
func newUnionFind(size int) *unionFind {
parent := make([]int, size)
for i := range parent {
parent[i] = i
}
return &union{
return &unionFind{
parent: parent,
}
}

func (u *union) find(i int) int {
func (u *unionFind) find(i int) int {
if u.parent[i] != i {
u.parent[i] = u.find(u.parent[i])
}
return u.parent[i]
}

func (u *union) unite(x, y int) {
func (u *unionFind) union(x, y int) {
u.parent[u.find(x)] = u.find(y)
}

0 comments on commit 714aefb

Please sign in to comment.