classSolution:defnumDistinctIslands(self,grid: List[List[int]]) ->int:defdepth_first_search(i:int,j:int,move:int): grid[i][j] =0 path.append(str(move)) directions = (-1,0,1,0,-1) for h inrange(4): x, y = i + directions[h], j + directions[h+1]if0<= x < m and0<= y < n and grid[x][y]:depth_first_search(x, y, h+1) path.append(str(-move))# Add the reverse move to path to differentiate shapes paths =set() path = [] m, n =len(grid),len(grid[0])for i, row inenumerate(grid):for j, value inenumerate(row):if value:depth_first_search(i, j, 0) paths.add("".join(path)) path.clear()returnlen(paths)