zoukankan      html  css  js  c++  java
  • 48. 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?

    此题可以用3*3的矩阵来举例子,发现可以先x,y互相先对掉,然后再左右对掉,代码如下:

    public class Solution {

        public void rotate(int[][] matrix) {

            for(int i=0;i<matrix.length;i++){

                for(int j=0;j<matrix[0].length;j++){

                    if(i>j){

                        int temp = matrix[i][j];

                        matrix[i][j] = matrix[j][i];

                        matrix[j][i] = temp;

                    }

                }

            }

            for(int i=0;i<matrix[0].length/2;i++){

                for(int j=0;j<matrix.length;j++){

                    int temp = matrix[j][i];

                    matrix[j][i] = matrix[j][matrix[0].length-i-1];

                    matrix[j][matrix[0].length-i-1]=temp;

                }

            }

        }

    }

  • 相关阅读:
    有关数据恢复的几个概念的理解
    cmsr 1.0.6
    Cmsr 1.0.5
    Cmsr 1.0.4
    vue中的v-model 与 .sync
    es6中clss做了些什么 怎么继承
    Cmsr 1.0.2
    Cmsr 1.0.1
    Cmsr 1.0.0
    VUE3.0新特性
  • 原文地址:https://www.cnblogs.com/codeskiller/p/6361210.html
Copyright © 2011-2022 走看看