import java.util.*; public class Solution { //记录四个方向 private int[][] dirs = new int[][] {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; private int n, m; public int solve (int[][] matrix) { //矩阵不为空 if (matrix.length == 0 || matrix[0].length == 0) return 0; int res = 0; n = matrix.length; m = matrix[0].length; /...