#include /** * 867. Transpose Matrix * Given a 2D integer array matrix, return the transpose of matrix. * The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices. */ class Solution { public: static std::vector> transpose(std::vector>& matrix) { const int m = matrix.size(), n = matrix.front().size(); std::vector> ret(n, std::vector(m)); for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) ret[j][i] = matrix[i][j]; return ret; } };