Leetcode Problem 694. Number of Distinct Islands
694. Number of Distinct Islands
AI Mock Interview
Leetcode Solutions
Hash By Path Signature
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize a set to store the unique hashes of islands.
Iterate over each cell in the grid.
If a cell is land (1) and not visited, start a DFS from that cell.
During DFS, keep track of the path by appending directions to a string as you move to new cells.
Also, append a special character (e.g., '0') when backtracking.
After completing the DFS for an island, add the path string to the set.
Continue until all cells are visited.
Return the size of the set, which represents the number of distinct islands.
Brute Force
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...