matrix[i][j]需要放在转置矩阵的(j,i)位置
public class Solution {
public int[][] Transpose(int[][] matrix) {
int rows = matrix.Length;
int columns = matrix[0].Length;
int[][] array2 = new int[columns][];
// 初始化内部数组(列数)
for (int i = 0; i < array2.Length; i++)
{
array2[i] = new int[rows]; // 每行rows个元素
}
for(int i=0;i<rows;i++){
for(int j=0;j<columns;j++){
array2[j][i]=matrix[i][j];
}
}
return array2;
}
}
标签:rows,matrix,转置,array2,867,int,Length,leetcode
From: https://blog.csdn.net/zhourongxiang1/article/details/139443834