MJay

959 본문

Programming/LeetCode

959

MJSon 2019. 10. 30. 10:18

959. Regions Cut By Slashes

Medium

42588FavoriteShare

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:

Union을 이용해서 key 와 value의 값이 같으면 그걸 return 하고 그거의 개수를 return 하면 된다. 

 

이 분 천재인거같다.

'Programming > LeetCode' 카테고리의 다른 글

931  (0) 2019.10.31
932  (0) 2019.10.30
1140  (0) 2019.10.29
877  (0) 2019.10.28
1161  (0) 2019.10.28