출처 : https://leetcode.com/problems/transpose-matrix/
Given a 2D integer array matrix
, return the transpose of matrix
.
The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.
class Solution {
public int[][] transpose(int[][] matrix) {
int[][] answer = new int[matrix[0].length][matrix.length];
int a = 0, b = 0, c = 0, d = 0;
while (d < matrix[0].length) {
if (c == matrix.length) {
a++;
b = 0;
c = 0;
d++;
} else {
answer[a][b] = matrix[c][d];
b++;
c++;
}
}
return answer;
}
}