21 / 21 个通过测试用例
状态:通过
执行用时:0 ms
内存消耗:36.2 MB
提交时间:6 月,3 周之前
class Solution {//本代码 来自[email protected]杨晓慧-Hepburnpublic void rotate(int[][] matrix) {int abs1 = 0;int abs2 = matrix.length - 1;int times = 0;while (abs1 <= abs2) {int p1 = abs1;int p2 = abs2;while (p1 != abs2) {// 转换的思路:// 1.先保存左上的值到临时变量// 2.左下--> 左上, 右下-->左上, 右上-->右下,临时变量内的左上-->右上int temp = matrix[abs1][p1]; //左上matrix[abs1][p1] = matrix[p2][abs1]; //左上 = 左下matrix[p2][abs1] = matrix[abs2][p2]; //左下 = 右下matrix[abs2][p2] = matrix[p1][abs2]; //右下 = 右上matrix[p1][abs2] = temp; //右上 = 左上p1 += 1;p2 -= 1;}abs1 += 1;abs2 -= 1;}}
}