Click here to see the full article post
Create parent[mn+1] and reserve parent to indicate whether a cell is water.
Since the init value of new int[m * n + 1] is 0, you can avoid the array initialization of complexity O(mn).
you can achieve O(klog(mn)).
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.