A common method to rotate the image

Source: Internet
Author: User

1 /*2 * Clockwise rotate3 * First reverse down, then swap the symmetry4 * 1 2 3 7 8 9 7 4 15 * 4 5 6 = 4 5 6 = 8 5 26 * 7 8 9 1 2 3 9 6 37 */8 voidRotate (vector<vector<int> > &matrix) {9 Reverse (Matrix.begin (), Matrix.end ());Ten      for(inti =0; I < matrix.size (); ++i) { One          for(intj = i +1; J < Matrix[i].size (); ++j) A swap (Matrix[i][j], matrix[j][i]); -     } - } the  - /* - * anticlockwise Rotate - * First reverse left-right, then swap the symmetry + * 1 2 3 3 2 1 3 6 9 - * 4 5 6 = 6 5 4 = 2 5 8 + * 7 8 9 9 8 7 1 4 7 A */ at voidAnti_rotate (vector<vector<int> > &matrix) { -      for(auto Vi:matrix) reverse (Vi.begin (), Vi.end ()); -      for(inti =0; I < matrix.size (); ++i) { -          for(intj = i +1; J < Matrix[i].size (); ++j) - swap (Matrix[i][j], matrix[j][i]); -     } in}

Here is a topic link to practice.

A common method to rotate the image

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.