列別:數(shù)組
題目: 867. 轉(zhuǎn)置矩陣
我的解題思路:
- 轉(zhuǎn)置矩陣就是交換矩陣的行索引宙地、列索引
- 定義一個(gè)新的二維數(shù)組,嵌套循環(huán)當(dāng)前二維數(shù)組,賦值新數(shù)組的行漏策、列與當(dāng)前數(shù)組相反
class Solution {
public int[][] transpose(int[][] A) {
int R = A.length, C = A[0].length;
int[][] result = new int[C][R];
for (int r = 0; r < R; ++r)
for (int c = 0; c < C; ++c) {
result[c][r] = A[r][c];
}
return result;
}
}