privatevoidprintEdge(int[][] matrix, int leftRow, int leftColumn, int rightRow, int rightColumn){ //行相等 if (leftRow == rightRow) { for (int i = leftColumn; i <= rightColumn; i++) { result[index++] = matrix[leftRow][i]; } //列相等 } elseif (leftColumn == rightColumn) { for (int i = leftRow; i <= rightRow; i++) { result[index++] = matrix[i][leftColumn]; } } else { //按照上、右、下、左的顺序打印即可 int curColumn = leftColumn; int curRow = leftRow;
while (curColumn != rightColumn) { result[index++] = matrix[leftRow][curColumn++]; }
while (curRow != rightRow) { result[index++] = matrix[curRow++][rightColumn]; }
while (curColumn != leftColumn) { result[index++] = matrix[rightRow][curColumn--]; }