Leetcode 48. Rotate Image | | Leetcode 48. Rotate Image 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution Version 1 123456789101112131415161718192021222324252627class Solution {public: void rotate(vector<vector<int>>& matrix) { int n = matrix.size(); for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { swap(matrix[i][j], matrix[j][i]); } } for(int k = 0; k < n; k++) { int i = 0; int j = n - 1; while(i < j) { swap(matrix[k][i], matrix[k][j]); i++; j--; } } } private: void swap(int& a, int& b) { int temp = a; a = b; b = temp; }}; Reference https://leetcode.com/problems/rotate-image/description/ 如果有收获,可以请我喝杯咖啡! 赏 微信打赏 支付宝打赏