leetcode867 C++ 32ms 转置矩阵

class Solution {
public:
    vector<vector<int>> transpose(vector<vector<int>>& A) {
        vector<vector<int>> res;
        if(A.empty() || A[0].empty()){
            return res;
        }
        int h = A.size();
        int w = A[0].size();
        vector<int> row;
        for(int ww=0;ww <w; ww++){
            row.clear();
            for(int hh=0; hh<h;hh++){
                row.push_back(A[hh][ww]);
            }
            res.push_back(row);
        }
        return res;
    }
};
posted @ 2018-08-04 16:35  一条图图犬  阅读(439)  评论(0编辑  收藏  举报