Leetcode - Shortest Path in Binary Matrix (Python)

preview_player
Показать описание
February 2021 Leetcode Challenge
Leetcode - Shortest Path in Binary Matrix #1091
Difficulty: Medium
Рекомендации по теме
Комментарии
Автор

Thank you for making my life easier with your clear and concise explanations.

sauravdeb
Автор

I was about to go crazy because I had a perfectly working bfs algorithm and I was getting a Time Limit Exception.
The culprit? line 23 on your code...

It completely makes sense to mark it as visited at that point because if we ever would get to that same cell after that, it's probably a longer path anyway.

Thank you for the vid Tim!

Автор

How did you know that your solution always produced the minimum count? Could there be a faster or slower path?

vinh
Автор

Is deque faster than list ? I used List

jjff
Автор

Nice explanation and I am also trying to solve a similar type of maze reading from a file. I also need to travel through 0s not 1s. But only right or left not diagonally. So My maze is as below : E is the entry and in any border if we hit any 0 i.e the exit. Currently only one exit at the last line. But there may be other exits too.
Input :
1E1111
101011
100001
110101
111101

Expected output :
Shortest path count and then
1E1111
1+1011
1++++1
1101+1
111101

I need to find shortest path and also I need to mark that short path with some symbols like + and also to print the maze at the end with those symbols updated ?
Any help on this would be appreciated ?
I could print steps count now with the algorim. How to mark the path with +signs and then print maze at the end ?

hymap
join shbcf.ru