Skip to content

Commit

Permalink
Create 867. Transpose Matrix (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 10, 2023
2 parents 7b76f25 + cf87be9 commit 1b240b1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 867. Transpose Matrix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
vector<vector<int>> transpose(vector<vector<int>>& matrix) {
int row = matrix.size();
int col = matrix[0].size();
// Create Transpose Matrix
vector<vector<int>> ans(col, vector<int>(row, 0));
// Insert In Transpose Matrix
for (int i = 0; i < row; i++)
for(int j = 0; j < col; j++)
ans[j][i] = matrix[i][j];

return ans;
}
};

0 comments on commit 1b240b1

Please sign in to comment.