题解 | #顺时针旋转矩阵#

顺时针旋转矩阵

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

#include <vector>

class Solution {

public:

    vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) {

        // write code here

        for(int i = 0; i < n; i++){

            for(int j = i; j < n; j++){

                swap(mat[i][j], mat[j][i]); //时间复杂度为O(N^2),空间复杂度为O(1);

            }

            reverse(mat[i].begin(), mat[i].end());

        }

        return mat;

    }

};

全部评论

相关推荐

流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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