773. Sliding Puzzle

BFS - grid data convert to String format

2*3 = 6, 6! permutation of the 6 numbers,

T: O(mn + mn*(mn!)),

S:O(mn + mn!)

pre calculate the swap position && new style BFS

key:

  1. how to define the final state? in[][] to String

  2. how to define the move?

visited use Set<String>, for certain String pattern, we have visited...

Last updated

Was this helpful?