Leetcode 48. 旋转图像

倒置一下,然后左右镜像一下

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        int L = matrix.size();
        for (int i = 0; i < L; ++i)
            for (int j = i + 1; j < L; ++j)
                swap(matrix[i][j], matrix[j][i]);
        for (int i = 0; i * 2 + 1 < L; ++i)
            for (int j = 0; j < L; ++j)
                swap(matrix[j][i], matrix[j][L - 1 - i]);
    }
};

猜你喜欢

转载自blog.csdn.net/bendaai/article/details/80153961
今日推荐