1.题目要求:
2.题目代码:
class Solution {
public:
vector<vector<int>> transpose(vector<vector<int>>& matrix) {
//把matrix的行变成result的列,把matrix的列变成result的行
vector<vector<int>> result;
result.resize(matrix[0].size());
for(int i = 0;i < matrix[0].size();i++){
result[i].resize(matrix.size());
}
int f = 0;
for(int j = 0;j < matrix[0].size();j++){
int index = 0;
for(int i = 0;i < matrix.size();i++){
result[f][index] = matrix[i][j];
index++;
}
f++;
}
return result;
}
};