Python solution leetcode:48. Rotate Image

Source: Internet
Author: User
Tags rotate image

    • Title Description: A two-dimensional array is rotated 90 degrees clockwise;

    • Ideas:
    1. For each lap of the array, the number of M control rings is used;
    2. The four elements of each lap are replaced clockwise, using Python's unpacking, using K to control the specific elements of each lap;
classSolution (Object):defRotate Self, matrix):""": Type Matrix:list[list[int]]: rtype:void do not return anything, modify matrix In-place instead.        """N= Len(Matrix) m= 0         whileM<=N/ 2: K=M whileK<N- 1 -M:matrix[m][k], Matrix[k][n-1-M], Matrix[n-1-M][n-1-K], Matrix[n-1-K][M]= \Matrix[n-1-K][M], matrix[m][k], matrix[k][n-1-M], Matrix[n-1-M][n-1-K] K+= 1M+= 1

Python solution leetcode:48. Rotate Image

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.