首页 > 学院 > 开发设计 > 正文

LeetCode 48. Rotate Image

2019-11-08 02:44:38
字体:
来源:转载
供稿:网友

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]);            }        }    }       };


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表