Very Simple Idea

  • 0

    Start DFS/BFS from the boundary nodes(Only the boundary nodes). => (i == 0 || j == 0 || i == row || j == col)

    1. Convert all the nodes reachable to some distinguishable character, like 'S'.
    2. All the remaining nodes are surrounded nodes.
    3. Scan the matrix and convert all the 'O' to 'X' and 'S' to 'O'.


Log in to reply

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