把矩阵转置。
思路:
列变行,行变列。
public int[][] transpose(int[][] matrix) {
int rows = matrix.length;
int cols = matrix[0].length;
int[][] res = new int[cols][rows];
for(int r = 0; r < rows; r ++) {
for(int c = 0; c < cols; c++) {
res[c][r] = matrix[r][c];
}
}
return res;
}