swift 旋转图像 LeetCode

给定一个 × n 的二维矩阵表示一个图像。

将图像顺时针旋转 90 度。

说明:

你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。

class Solution {
    func rotate(_ matrix: inout [[Int]]) {
        let temp = matrix
        let len = matrix.count
        for i in 0..<len {
            for j in 0..<len {
                matrix[j][len - 1 - i] = temp[i][j]
            }
        }
        
    }
}

猜你喜欢

转载自blog.csdn.net/shashen12300/article/details/82427216