Leetcode - 967 Transpose Matrix (Easy)
题目描述:行列互换。
Input: [[1,2,3],[4,5,6],[7,8,9]]
Output: [[1,4,7],[2,5,8],[3,6,9]]
public int[][] transpose(int[][] A) {
int[][] res = new int[A[0].length][A.length];
for (int i = 0; i < A.length; i++) {
for (int j = 0; j < A[0].length; j++) {
res[j][i] = A[i][j];
}
}
return res;
}