首页 > 代码库 > Rotate Image

Rotate Image

将图片旋转90°,实际上就是在操作数组,感觉实际中canvas可以用到。

 

 

 

public class Solution {    public void rotate(int[][] matrix) {        if (matrix.length == 1) {            return;        } else {            int n = matrix.length;            for (int i = 0; i < n; i++) {                for (int a = 0; a < i; a++) {                    matrix[a][i] = matrix[a][i] + matrix[i][a];                    matrix[i][a] = matrix[a][i] - matrix[i][a];                    matrix[a][i] = matrix[a][i] - matrix[i][a];                }            }            int max = (n & 1) == 1 ? n - 1 : n;            for (int i = 0; i < n; i++) {                for (int a = 0; a < max - a; a++) {                    matrix[i][a] = matrix[i][a] + matrix[i][n - a - 1];                    matrix[i][n - a - 1] = matrix[i][a] - matrix[i][n - a - 1];                    matrix[i][a] = matrix[i][a] - matrix[i][n - a - 1];                }            }        }    }}

 

Rotate Image