class Solution { public: void rotate(vector<vector<int> > &matrix) { int n = matrix.size(); int end = n / 2; for (int i=0; i<end; i++) { for (int j=i; j < n - i - 1; j++) { int a = matrix[i][j]; int b = matrix[j][n-1-i]; int c = matrix[n-1-i][n-1-j]; int d = matrix[n-1-j][i]; matrix[i][j] = d; matrix[j][n-1-i] = a; matrix[n-1-i][n-1-j] = b; matrix[n-1-j][i] = c; } } } };
水一发
LeetCode Rotate Image,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/lailailai/p/3854482.html