Posted on

Description

Submission

class Solution {
public:
    vector<vector<int>> transpose(vector<vector<int>>& matrix) {
        int m = matrix.size();
        int n = matrix[0].size();

        vector<vector<int>> ret(n, vector<int>(m));

        for(int i = 0; i < m; ++i) {
            for(int j = 0; j < n; ++j) {
                ret[j][i] = matrix[i][j];
            }
        }
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *