Leetcode 48. Rotate Image My submissions Question (matrix rotation)

Source: Internet
Author: User
Tags rotate image

Title: Give a matrix, rotate it clockwise 90 °.

Problem Analysis: The Pass method is to transpose the matrix first, then reverse each line, or reverse each column first and then transpose it. I just want to say "It ' s amazing!". (Forgivig my poor english!)

The code is as follows (it doesn't matter how the code is written!) ):

Class Solution {public:    void rotate (vector<vector<int>>& matrix) {        int r=matrix.size ();        int c=matrix[0].size ();        for (int. i=0;i<r;++i) {for            (int j=i+1;j<c;++j)                swap (matrix[i][j],matrix[j][i]);            for (int j=0,k=c-1;j<k;++j,--k)                swap (matrix[i][j],matrix[i][k]);}}    ;

  

Leetcode 48. Rotate Image My submissions Question (matrix rotation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.