[leetcode]867. Transpose Matrix
Analysis
ummmm~—— [ummmm~]
Given a matrix A, return the transpose of A.
The transpose of a matrix is the matrix flipped over it’s main diagonal, switching the row and column indices of the matrix.
矩阵转置~
Implement
class Solution {
public:
vector<vector<int>> transpose(vector<vector<int>>& A) {
vector<vector<int>> res;
int len1 = A.size();
int len2 = A[0].size();
res.resize(len2);
for(int i=0; i<len2; i++){
res[i].resize(len1);
}
for(int i=0; i<len1; i++){
for(int j=0; j<len2; j++){
res[j][i] = A[i][j];
}
}
return res;
}
};