Skip to content

Latest commit

 

History

History
241 lines (104 loc) · 3.3 KB

File metadata and controls

241 lines (104 loc) · 3.3 KB

中文文档

Description

In a N x N grid composed of 1 x 1 squares, each 1 x 1 square consists of a /, \, or blank space.  These characters divide the square into contiguous regions.

(Note that backslash characters are escaped, so a \ is represented as "\\".)

Return the number of regions.

 

Example 1:

Input:

[

  " /",

  "/ "

]

Output: 2

Explanation: The 2x2 grid is as follows:



Example 2:

Input:

[

  " /",

  "  "

]

Output: 1

Explanation: The 2x2 grid is as follows:



Example 3:

Input:

[

  "\\/",

  "/\\"

]

Output: 4

Explanation: (Recall that because \ characters are escaped, "\\/" refers to \/, and "/\\" refers to /\.)

The 2x2 grid is as follows:



Example 4:

Input:

[

  "/\\",

  "\\/"

]

Output: 5

Explanation: (Recall that because \ characters are escaped, "/\\" refers to /\, and "\\/" refers to \/.)

The 2x2 grid is as follows:



Example 5:

Input:

[

  "//",

  "/ "

]

Output: 3

Explanation: The 2x2 grid is as follows:



 

Note:

    <li><code>1 &lt;= grid.length == grid[0].length &lt;= 30</code></li>
    
    <li><code>grid[i][j]</code> is either <code>&#39;/&#39;</code>, <code>&#39;\&#39;</code>, or <code>&#39; &#39;</code>.</li>
    

Solutions

Python3

Java

...