题解 | 顺时针旋转矩阵

顺时针旋转矩阵

https://www.nowcoder.com/practice/2e95333fbdd4451395066957e24909cc

#include <vector>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param mat int整型vector<vector<>> 
     * @param n int整型 
     * @return int整型vector<vector<>>
     */
    vector<vector<int> > rotateMatrix(vector<vector<int> >& mat, int n) {
        vector<vector<int>> res(n, vector<int>(n, 0)); 

        for(int i =0  ; i < n;i++){
            for(int j =0 ; j< n;j++){
                res[i][j]=mat[n-1-j][i];
                //cout<<res[i][j]<<endl;
            }
        }
        return res; 
    }
};

处理一下遍历方向

全部评论

相关推荐

点赞 评论 收藏
分享
皮格吉:不,有的厂子面试无手撕,可以试试。都是一边学一边面。哪有真正准备好的时候,别放弃
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务