var rotate = function(matrix) { const n = matrix.length; for (let i = 0; i < Math.floor(n / 2); ++i) { for (let j = 0; j < Math.floor((n + 1) / 2); ++j) { const temp = matrix[i][j]; matrix[i][j] = matrix[n - j - 1][i]; matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; matrix[j][n - i - 1] = temp; } }};作者:LeetCode-Solution链接:https://leetcode.cn/problems/rotate-image/solution/xuan-zhuan-tu-xiang-by-leetcode-solution-vu3m/来源:力扣(LeetCode)著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。