Python--n*n matrix rotated 90 degrees clockwise

Source: Internet
Author: User

First design ideas, take 4*4 matrix as an example, it is not difficult to find in fact, if the following the same color row and column exchange, in fact, can achieve the goal

It is not difficult to find that the implementation has the following rules:

i = 0
j = A
i = 1
j = 2, 3
I= 2
j = 3

DATA[I][J] and Data[j][i] can be exchanged, but the exchange will think that there is a third variable to implement the way of exchange, so the implementation code is as follows:

You are not mistaken, so it has been done, is not very magical! If you want to implement N*n, modify the code can be, here I do not add.

    

  

Python--n*n matrix rotated 90 degrees clockwise

Related Article

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.