Swift solution


  • 0
    U

    Re: A common method to rotate the image

    func rotate(_ matrix: inout [[Int]])
    {
    var s : Int = 0
    var e : Int = matrix.count-1

        while s<e
        {
            
            swap(&matrix[s], &matrix[e])
            s = s + 1
            e = e - 1
        }
        
        for i in stride(from: 0, to: matrix.count, by: 1)
        {
            for j in stride(from: i+1, to: matrix[i].count, by: 1)
            {
                swap(&matrix[j][i], &matrix[i][j])
            }
            
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.