959. Regions Cut By Slashes Medium

@problem@discussion
#Depth-First Search#Breadth-First Search#Union Find#Graph



1/**
2 * [959] Regions Cut By Slashes
3 *
4 * An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions.
5 * Given the grid grid represented as a string array, return the number of regions.
6 * Note that backslash characters are escaped, so a '\' is represented as '\\'.
7 *  
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/1.png" style="width: 200px; height: 200px;" />
10 * Input: grid = [" /","/ "]
11 * Output: 2
12 * 
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/2.png" style="width: 200px; height: 198px;" />
15 * Input: grid = [" /","  "]
16 * Output: 1
17 * 
18 * Example 3:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/4.png" style="width: 200px; height: 200px;" />
20 * Input: grid = ["/\\","\\/"]
21 * Output: 5
22 * Explanation: Recall that because \ characters are escaped, "\\/" refers to \/, and "/\\" refers to /\.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	n == grid.length == grid[i].length
28 * 	1 <= n <= 30
29 * 	grid[i][j] is either '/', '\', or ' '.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/regions-cut-by-slashes/
35// discuss: https://leetcode.com/problems/regions-cut-by-slashes/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn regions_by_slashes(grid: Vec<String>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_959() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.