只是思路:
Let a list L be a list of list of cell representing valid non crossing paths
Let a matrix of cells representing the board
Let set S representing cells that have been collected in previous valid path
While L's size is smaller than k
Let set visited representing a set of cells that have been visited
for current bfs path search
Let currentPath representing a list of cells,
For each cell C of board,
visited.put(C)
If C is not in set, dfs(currentPath, visited, C)
visited.remove(C)
bfs(List currentPath, Set visited, Cell C) //Base condition If C is end, add currentPath to L add all cells of currentPath to S // avoid crossing return Let list be a list of cells that can be navigated For v of each cell of list If v is not in S, currentPath.add(v) visited.add(v) bfs(currentPath, visited, v) visited.remove(v) This shall work. It's not tricky but just tedious. Leetcode middle level. | |