LintCode 161-旋转图像

来源:互联网 发布:php 数组长度函数 编辑:程序博客网 时间:2024/05/29 07:07

本人电子系,只为一学生。心喜计算机,小编以怡情。


  static  public void rotate(int[][] matrix) {        // write your code here        if(matrix.length==0) return ;        int [][]temp=new int[matrix.length][matrix[0].length];        for (int i = 0, m=matrix[0].length-1; i < matrix.length&& m>=0; i++,m--)            for (int j = 0,n=0; j < matrix[0].length&&n<matrix.length; j++,n++) {                temp[n][m]=matrix[i][j];        //matrix = temp        for (int i = 0; i < temp.length; i++) {            for (int j = 0; j < temp[0].length; j++) {                matrix[i][j]=temp[i][j];            }        }    }