Skip to content

Commit 0089697

Browse files
refactor 505
1 parent 09dc3b9 commit 0089697

File tree

1 file changed

+0
-47
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-47
lines changed

src/main/java/com/fishercoder/solutions/_505.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,6 @@
33
import java.util.LinkedList;
44
import java.util.Queue;
55

6-
/**
7-
* 505. The Maze II
8-
*
9-
* There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right,
10-
* but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.
11-
* Given the ball's start position, the destination and the maze, find the shortest distance for the ball to stop at the destination. The distance is defined by the number of empty spaces traveled by the ball from the start position (excluded) to the destination (included). If the ball cannot stop at the destination, return -1.
12-
* The maze is represented by a binary 2D array. 1 means the wall and 0 means the empty space. You may assume that the borders of the maze are all walls. The start and destination coordinates are represented by row and column indexes.
13-
14-
Example 1
15-
16-
Input 1: a maze represented by a 2D array
17-
18-
0 0 1 0 0
19-
0 0 0 0 0
20-
0 0 0 1 0
21-
1 1 0 1 1
22-
0 0 0 0 0
23-
24-
Input 2: start coordinate (rowStart, colStart) = (0, 4)
25-
Input 3: destination coordinate (rowDest, colDest) = (4, 4)
26-
27-
Output: 12
28-
Explanation: One shortest way is : left -> down -> left -> down -> right -> down -> right.
29-
The total distance is 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12.
30-
31-
Example 2
32-
33-
Input 1: a maze represented by a 2D array
34-
35-
0 0 1 0 0
36-
0 0 0 0 0
37-
0 0 0 1 0
38-
1 1 0 1 1
39-
0 0 0 0 0
40-
41-
Input 2: start coordinate (rowStart, colStart) = (0, 4)
42-
Input 3: destination coordinate (rowDest, colDest) = (3, 2)
43-
44-
Output: -1
45-
Explanation: There is no way for the ball to stop at the destination.
46-
47-
Note:
48-
There is only one ball and one destination in the maze.
49-
Both the ball and the destination exist on an empty space, and they will not be at the same position initially.
50-
The given maze does not contain border (like the red rectangle in the example pictures), but you could assume the border of the maze are all walls.
51-
The maze contains at least 2 empty spaces, and both the width and height of the maze won't exceed 100.
52-
*/
536
public class _505 {
547

558
public static class Solution1 {

0 commit comments

Comments
 (0)