DFS:需要额外维护一个path数组来存储路径,以及使用flag来判断是否已经到达终点 import java.util.*; public class Main { private static int[][] dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; private static int[][] grid; private static int h, w; private static boolean[][] visited; private static List<int[]> path; ...