Analysis:
we must use breadth first traversal, otherwise the recursion stack depth will be exceeded.
use touchWall flag to determine whether this area can be marked
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class Solution(object): |