LeetCode 48. Rotate Image

来源:互联网 发布:kali linux和centos 编辑:程序博客网 时间:2024/06/05 02:42

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?

class Solution {public:    void rotate(vector<vector<int>>& matrix) {        int length = matrix[0].size();        for(int i = 0; i < length / 2; i ++){            swap(matrix[i],matrix[length - 1 - i]);        }                for(int i = 0; i < length; i ++){            for(int j = i + 1; j < length; j ++){                swap(matrix[i][j],matrix[j][i]);            }        }    }       };



0 0
原创粉丝点击