@@ -0,0 +1,2031 @@
+import java.util.LinkedList;%0Aimport java.util.Queue;%0A%0Apublic class Maze %7B%0A    public static final void main(String%5B%5D args) %7B%0A        int%5B%5D%5B%5D maze = new int%5B%5D%5B%5D %7B%0A                %7B0, 0, 1, 0, 0%7D,%0A                %7B0, 0, 0, 0, 0%7D,%0A                %7B0, 0, 0, 1, 0%7D,%0A                %7B1, 1, 0, 1, 1%7D,%0A                %7B0, 0, 0, 0, 0%7D%0A        %7D;%0A%0A        System.out.println(findPath(maze));%0A    %7D%0A%0A    static class Point %7B%0A        int x, y;%0A        int len;%0A        String path;%0A%0A        public Point(int x, int y, int len, String path) %7B%0A            this.x = x;%0A            this.y = y;%0A            this.len = len;%0A            this.path = path;%0A        %7D%0A    %7D%0A%0A    static final int%5B%5D%5B%5D DIR = new int%5B%5D%5B%5D %7B%7B-1,0%7D, %7B1,0%7D, %7B0,1%7D, %7B0,-1%7D%7D;%0A    static final Character%5B%5D DIR_CHAR = new Character%5B%5D%7B'u', 'd', 'r', 'l'%7D;%0A%0A    public static String findPath(int%5B%5D%5B%5D maze) %7B%0A        if (maze.length == 0 %7C%7C maze%5B0%5D.length == 0) return %22%22;%0A        int n = maze.length, m = maze%5B0%5D.length;%0A        boolean%5B%5D%5B%5D visited = new boolean%5Bn%5D%5Bm%5D;%0A        Queue%3CPoint%3E q = new LinkedList%3C%3E();%0A        visited%5B0%5D%5B0%5D = true;%0A        String path = %22%22;%0A        q.offer(new Point(0, 0, 0, path));%0A        int min = Integer.MAX_VALUE;%0A%0A        while(!q.isEmpty()) %7B%0A            Point p = q.poll();%0A            for (int i = 0; i %3C 4; i++) %7B%0A                int newX = p.x + DIR%5Bi%5D%5B0%5D;%0A                int newY = p.y + DIR%5Bi%5D%5B1%5D;%0A                int newLen = p.len + 1;%0A                String newPath = p.path + DIR_CHAR%5Bi%5D;%0A                if (newX %3E= 0 && newX %3C n && newY %3E= 0 && newY %3C m && maze%5BnewX%5D%5BnewY%5D == 0 && !visited%5BnewX%5D%5BnewY%5D) %7B%0A                    if (newX == n - 1 && newY == m - 1) %7B%0A                        if (newLen %3C min) %7B%0A                            min = newLen;%0A                            path = newPath;%0A                        %7D%0A                    %7D%0A                    visited%5BnewX%5D%5BnewY%5D = true;%0A                    q.offer(new Point(newX, newY, newLen, newPath));%0A                %7D%0A            %7D%0A        %7D%0A%0A        return path;%0A    %7D%0A%7D%0A

Add snapchat