This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maxDistance(self, grid): | |
rows = len(grid) | |
if rows == 0: | |
return -1 | |
cols = len(grid[0]) | |
lands = collections.deque() | |
maxDistance = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
# Time complexity: O(rows * cols) -> each cell is visited at least once | |
# Space complexity: O(rows * cols) -> in the worst case if all the oranges are rotten they will be added to the queue | |
class Solution: | |
def orangesRotting(self, grid): | |
# number of rows | |
rows = len(grid) |