力扣链接:https://leetcode.cn/problems/rotate-matrix-lcci/description/
本人题解:
js
/**
* @param {number[][]} matrix
* @return {void} Do not return anything, modify matrix in-place instead.
*/
var rotate = function (matrix) {
const x = matrix.length || 0;
const y = x > 0 ? matrix[0]?.length : 0;
if (x === 0) return [];
if (y === 1) return matrix;
for (let i = 0; i < x; i++) {
for (let j = i; j < y; j++) {
const temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
return matrix.map((item) => item.reverse());
};