zoukankan      html  css  js  c++  java
  • leetCode 48.Rotate Image (旋转图像) 解题思路和方法

    Rotate Image

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

    Rotate the image by 90 degrees (clockwise).

    Follow up:

    Could you do this in-place?


    思路:事实上就是旋转数组。没有什么难度。代码例如以下:

    public class Solution {
        public void rotate(int[][] matrix) {
        	int[][] a = new int[matrix.length][matrix.length];
        	//实现深拷贝
        	for(int i = 0; i < matrix.length; i++){
        		for(int j = 0; j < matrix.length;j++){
        			a[i][j] = matrix[i][j];
        		}
        	}
        	//数据旋转
            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("");
            }
        }
    }


  • 相关阅读:
    国庆·生日
    国足
    Eason's concert
    今天的斩获
    The 4400
    闷热
    24
    一直登录不了。。。原来是因为。。。
    黄色暴雨警告
    绝密飞行
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5203049.html
Copyright © 2011-2022 走看看