0
Leetcode Problem 711. Number of Distinct Islands II
711. Number of Distinct Islands II
AI Mock Interview
Leetcode Solutions
Canonical Hash for Distinct Island Shapes
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Iterate over each cell in the grid.
If the cell is part of an island (value is 1) and has not been seen before, perform a Depth-First Search (DFS) to explore the entire island.
During the DFS, record the cells that make up the island.
For each island, generate all possible rotations and reflections.
Normalize these shapes by translating them so that the bottom-left-most coordinate is at (0, 0).
Sort the coordinates of each transformed shape and choose the smallest one as the canonical representation.
Add the canonical representation of the island to a set to ensure distinct shapes are counted.
Return the size of the set, which represents the number of distinct islands.
Distinct Islands with String Serialization
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...