阅读量:83
在Java中,可以通过以下方法将二维数组进行转置:
public static int[][] transpose(int[][] matrix) {
int rows = matrix.length;
int cols = matrix[0].length;
int[][] transposedMatrix = new int[cols][rows];
for (int i = 0; i < rows class="hljs-keyword">for (int j = 0; j < cols xss=removed class="hljs-keyword">return transposedMatrix;
}
调用此方法,可以将一个二维数组转置,并返回转置后的二维数组。