Why not dfs?


  • 0
    S

    Maintain max[i][j] as the maximum height (with water) for cell i, j. Then using dfs (similar to number of islands) to decrease max[i][j].

    i.e. if max[i][j] is decreased then do dfs to check if its neigbhours' max will be updated.

    I think the logic is correct, but my code failed on large input, stack overflow.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.