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;

                }

            }

        }

    }

  • 相关阅读:
    22_selenium_使用cookie直接登录
    21_无头模式
    自动化测试-设计模式-介绍
    Doorls
    pytest-Allure报告
    pytest-架构1
    pytest-第一次学习梳理
    web测试
    测试-工时评估
    封装pyuic5转换ui文件的脚本
  • 原文地址:https://www.cnblogs.com/codeskiller/p/6361210.html
Copyright © 2011-2022 走看看