当前位置: 代码迷 >> 综合 >> leetcode 48. Rotate Image (medium)
  详细解决方案

leetcode 48. Rotate Image (medium)

热度:14   发布时间:2024-01-05 00:33:50.0

旋转矩阵
将矩阵以二维数组的下标为值画出来,对比两个矩阵的下标变化,就能推出规律了

class Solution
{public:void rotate(vector<vector<int>> &m){int n = m.size();for (int i = 0; i < n; i++)for (int j = 0; j < i; j++)swap(m[i][j], m[j][i]);for (int i = 0; i < n; i++)reverse(m[i].begin(), m[i].end());}
};
  相关解决方案