mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
Add solution to 'a lot' of problems
This commit is contained in:
16
Easy/transpose-matrix/solution.cpp
Normal file
16
Easy/transpose-matrix/solution.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
std::vector<std::vector<int>> transpose(std::vector<std::vector<int>> &matrix) {
|
||||
std::vector<std::vector<int>> trans(matrix[0].size(), std::vector<int>(matrix.size()));
|
||||
|
||||
for (int i = 0; i < matrix.size(); ++i) {
|
||||
for (int j = 0; j < matrix[0].size(); ++j) {
|
||||
trans[j][i] = matrix[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
return trans;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user