LeetCode694. Number of Distinct Islands - 彻底掌握并查集(Union Find)系列题7

该博客介绍了如何解决LeetCode694问题,即计算二进制矩阵中不同形状的岛屿数量。通过使用并查集算法,首先合并相连的陆地区域形成岛屿,然后通过平移岛屿并比较其形状来确定独特的岛屿。文章详细解释了如何选择基点平移岛屿,以及如何利用并查集的父节点作为基点进行坐标转换。最后,通过将转换后的岛屿坐标存入集合以消除重复,从而得到独特岛屿的数量。
摘要由CSDN通过智能技术生成

You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

An island is considered to be the same as another if and only if one island can be translated (and not rotated or reflected) to equal the other.

Return the number of distinct islands.

Example 1:

Input: grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]
Output: 1

Example 2:

Input:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值