Number of Islands complexity
stepanhruda opened this issue · 2 comments
stepanhruda commented
Currently complexity: O((n^2)!)
- Tiles are switched to 0 once visited, so they cannot be visited again. Although the search can look into 4 directions for each tile, it doesn't keep going.
- The instructions don't say that the board is a square (although it is in the example).
Suggested complexity: O(mn)
soapyigu commented
Hi,
For 1, I did it to track if a tile is visited or not, and that is necessary for DFS;
For 2, you are right, O(mn) is more accurate.
Thank you for your suggestions,
Yi
stepanhruda commented
Oh I agree with the approach, just meant to back up why I thought the complexity was lower. I see you already merged a fix.