Rust using queue and set
Code\n\nuse std::collections::VecDeque;\nuse std::collections::HashSet;\n\nimpl Solution {\n    pub fn nearest_exit(maze: Vec<Vec<char>>, entrance: Vec<i32>) ->
# Code\n```\nuse std::collections::VecDeque;\nuse std::collections::HashSet;\n\nimpl Solution {\n    pub fn nearest_exit(maze: Vec<Vec<char>>, entrance: Vec<i32>) -> i32 {\n        let mut queue = VecDeque::new();\n        let mut visited = HashSet::new();\n        queue.push_back((entrance[0] as usize, entrance[1] as usize, 0));\n        while !queue.is_empty() {\n            while let Some((i, j, c)) = queue.pop_front() {\n                if !visited.insert((i, j)) {\n                    continue;\n                }\n                if i == 0 || i == maze.len() - 1 || j == 0 || j == maze[0].len() - 1 {\n                    if i != entrance[0] as usize || j != entrance[1] as usize {\n                        return c;\n                    }\n                }\n                if maze[i][j] == \'.\' {\n                    if i > 0 && maze[i - 1][j] == \'.\' {\n                        queue.push_back((i - 1, j, c + 1));\n                    }\n                    if i < maze.len() - 1 && maze[i + 1][j] == \'.\' {\n                        queue.push_back((i + 1, j, c + 1));\n                    }\n                    if j > 0 && maze[i][j - 1] == \'.\' {\n                        queue.push_back((i, j - 1, c + 1));\n                    }\n                    if j < maze[0].len() - 1 && maze[i][j + 1] == \'.\' {\n                        queue.push_back((i, j + 1, c + 1));\n                    }\n                }\n            }\n        }\n        -1\n    }\n}\n```
['Rust']