halfrost / LeetCode-Go

✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
https://books.halfrost.com/leetcode
MIT License
32.76k stars 5.68k forks source link

a problem with code #197

Open zhangbo2008 opened 2 years ago

zhangbo2008 commented 2 years ago

https://github.com/halfrost/LeetCode-Go/blob/f0792d1179b1a6ab12fb9f906a3fc40ef68f9a80/template/UnionFind.go#L104

感觉这个地方应该是:

应该是 uf.count[proot]== len(uf.parent)-1

hekai000 commented 3 days ago

对,这里有问题,应该是: if uf.count[proot ] == len(uf.parent)-1 { //proot is the root of the tree, no need to merge } else if uf.count[qroot] == len(uf.parent)-1 { proot , qroot = qroot, proot } else if uf.count[qroot] > uf.count[proot] { proot , qroot = qroot, proot }

haowan1015 commented 3 days ago

呵呵,来信收到,谢谢

xiaokuer commented 3 days ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

halfrost commented 17 hours ago

@zhangbo2008 我这里的 proot 和 qroot 只是代表 index,存的 count 是在 uf.count[proot] 中。