947. Most Stones Removed with Same Row or Column

Description

Here

Intuition

首先我们定义任意两点为connect如果两点row或者col相同

那么问题转化为,如何优化出一种算法,使得在每个连通的component里,最终只剩下一个点

那么,这就是一个Union Find问题

进一步思考:

看似是rowcol将点连在一起,其实反过来想,是点把rowcol合并在了一起

Pitfall

Solution

Reference

results matching ""

    No results matching ""