13、Rotate Image

![Uploading 屏幕快照 2016-08-05 11.28.09_715873.png . . .]##Problem Description
You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

Analyze

13、Rotate Image_第1张图片

Code

class Solution {
    func rotate(inout matrix: [[Int]]) {
        let lines = matrix.count
        
        func swapInMatrix(left: (Int, Int), right: (Int, Int)) {
            let temp = matrix[left.0][left.1]
            matrix[left.0][left.1] = matrix[right.0][right.1]
            matrix[right.0][right.1] = temp
        }
      
        for line in 0..

你可能感兴趣的:(13、Rotate Image)