diff options
author | crupest <crupest@outlook.com> | 2021-02-25 16:52:17 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-25 16:52:17 +0800 |
commit | 5f8f15af534e4aab617ba07d9eae3665b6a06db7 (patch) | |
tree | 6814cfc36a2ebe34d8fede4b1842fbe9ee89c3cf /leetcode/cpp/867.cpp | |
parent | 07289d1382e192bcde6df1d0aa0e863a67458620 (diff) | |
download | solutions-5f8f15af534e4aab617ba07d9eae3665b6a06db7.tar.gz solutions-5f8f15af534e4aab617ba07d9eae3665b6a06db7.tar.bz2 solutions-5f8f15af534e4aab617ba07d9eae3665b6a06db7.zip |
Add leetcode 867.
Diffstat (limited to 'leetcode/cpp/867.cpp')
-rw-r--r-- | leetcode/cpp/867.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/leetcode/cpp/867.cpp b/leetcode/cpp/867.cpp new file mode 100644 index 0000000..9efd176 --- /dev/null +++ b/leetcode/cpp/867.cpp @@ -0,0 +1,20 @@ +#include <vector>
+
+using std::vector;
+
+class Solution {
+public:
+ vector<vector<int>> transpose(vector<vector<int>> &matrix) {
+ const int row_count = matrix.size();
+ const int col_count = matrix.front().size();
+
+ vector<vector<int>> result(col_count, std::vector<int>(row_count));
+
+ for (int i = 0; i < row_count; i++)
+ for (int j = 0; j < col_count; j++) {
+ result[j][i] = matrix[i][j];
+ }
+
+ return result;
+ }
+};
|