[leetcode] UnionFind 都在子节点怎么合并

楼主: Wardyal (Wardyal)   2024-08-29 17:37:43
刚刚在看今天的LeetCode
https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/
有一笔我刚才一直错
看了一下是我要合并5和8
https://imgur.com/ZdserUp
标准答案是 :
0 1 1 3 4 0 0 1 1 3
0 0 1 3 4 0 0 1 1 3
把1的Union值改成0
不过我写成 :
0 1 1 3 4 0 0 1 1 3
0 1 1 3 4 0 0 1 0 3
直接把8的Union改成0
作者: oin1104 (是oin的说)   2024-08-29 17:39:00
6,4跟1,4 然后1,4交1,0
作者: JIWP (JIWP)   2024-08-29 17:39:00
(6,4)(1,4)(1,0)(0,0)
楼主: Wardyal (Wardyal)   2024-08-29 17:41:00
我find没写好 我后来改了
作者: oin1104 (是oin的说)   2024-08-29 17:43:00
恭喜成功了吗
楼主: Wardyal (Wardyal)   2024-08-29 17:45:00
刚刚成功了 只是不知道为什么是把1>0
作者: sustainer123 (caster)   2024-08-29 17:46:00
大师
作者: oin1104 (是oin的说)   2024-08-29 17:47:00
大师
作者: dont   2024-08-29 17:58:00
合并让root最终指向同一点 root1改0之后find 0125678都会是0

Links booklink

Contact Us: admin [ a t ] ucptt.com