Leetcode 48.Rotate image (rotated image) thinking and method of solving problems

Source: Internet
Author: User
Tags rotate image
Rotate Image

You are given a n x n 2D matrix representing an image.

Rotate the image by degrees (clockwise).

Follow up:

Could do this in-place?


Idea: Actually is the rotation array, no difficulty, the code is as follows:

public class Solution {public    void rotate (int[][] matrix) {    int[][] a = new int[matrix.length][matrix.length];
  //implement deep copy for    (int i = 0; i < matrix.length; i++) {for    (int j = 0; J < matrix.length;j++) {    A[i][j] = Matr IX[I][J];    }    }    Data rotation for        (int i = 0; i < a[0].length; i++) {            int k = 0;            for (int j = a.length-1; J >=0; j--) {                matrix[i][k++] = a[j][i];                System.out.print (A[j][i] + "");            }            System.out.println ("");}}    


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Leetcode 48.Rotate image (rotated image) thinking and method of solving problems

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.