content: public class Solution {
      public int shortestDistance(int[][] maze, int[] start, int[] dest) {
          int[][] distance = new int[maze.length][maze[0].length];
          boolean[][] visited = new boolean[maze.length][maze[0].length];
          for (int[] row: distance)
              Arrays.fill(row, Integer.MAX_VALUE);
          distance[start[0]][start[1]] = 0;
          dijkstra(maze, distance, visited);
          return distance[dest[0]][dest[1]] == Integer.MAX_VALUE ? -1 : distance[dest[0]][dest[1]];
      }
      public int[] minDistance(int[][] distance, boolean[][] visited) {
          int[] min={-1,-1};
          int min_val = Integer.MAX_VALUE;
          for (int i = 0; i < distance.length; i++) {
              for (int j = 0; j < distance[0].length; j++) {
                  if (!visited[i][j] && distance[i][j] < min_val) {
                      min = new int[] {i, j};
                      min_val = distance[i][j];
                  }
              }
          }
          return min;
      }
      public void dijkstra(int[][] maze, int[][] distance, boolean[][] visited) {
          int[][] dirs={{0,1},{0,-1},{-1,0},{1,0}};
          while (true) {
              int[] s = minDistance(distance, visited);
              if (s[0] < 0)
                  break;
              visited[s[0]][s[1]] = true;
              for (int[] dir: dirs) {
                  int x = s[0] + dir[0];
                  int y = s[1] + dir[1];
                  int count = 0;
                  while (x >= 0 && y >= 0 && x < maze.length && y < maze[0].length && maze[x][y] == 0) {
                      x += dir[0];
                      y += dir[1];
                      count++;
                  }
                  if (distance[s[0]][s[1]] + count < distance[x - dir[0]][y - dir[1]]) {
                      distance[x - dir[0]][y - dir[1]] = distance[s[0]][s[1]] + count;
                  }
              }
          }
      }
  }