aboutsummaryrefslogtreecommitdiff
path: root/store/works/solutions/leetcode/cpp/867.cpp
blob: 9efd1760cacf023d543aa0f5a404e4fb044141ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
  }
};