leetcode 48. Rotate Image-矩阵旋转

原创 2016年06月02日 09:21:20
原题链接:48. Rotate Image

【思路-Java】


 矩阵的顺时针90°旋转,关键是找到坐标关系。本题中 n 的值提前减1了,所以在下面的运算中就没有减1了。

public class Solution {
    public void rotate(int[][] matrix) {
        for(int i=0, temp=0, n=matrix.length-1; i<=n/2; i++) {
            for(int j=i; j<n-i; j++) {
                temp = matrix[j][n-i];
                matrix[j][n-i] = matrix[i][j];
                matrix[i][j] = matrix[n-j][i];
                matrix[n-j][i] = matrix[n-i][n-j];
                matrix[n-i][n-j] = temp;
            }
        }
    }
}
20 / 20 test cases passed. Runtime: 0 ms  Your runtime beats 25.77% of javasubmissions.
 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

leetcode 48. Rotate Image(矩阵旋转)

You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise)....

Leetcode #48. Rotate Image 图像旋转 解题报告

1 解题思想这道题呢,是让一个图像(二维数组),翻转90度,原地的这道题如果不要求原地,那么我们可以重新开一个数组填入,单着明显不满足原地移动的要求。仔细观察,二维数组我们可以看成是一圈,一圈的数据,...

leetcode解题之48. Rotate Image java版(旋转图像)

leetcode解题之48. Rotate Image java版(旋转图像)

LeetCode 第 48 题(Rotate Image)

LeetCode 第 48 题(Rotate Image) You are given an n x n 2D matrix representing an image. Rotate th...

DAY21:leetcode #48 Rotate Image

You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise...

Leetcode 48. Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Fo...

48. Rotate Image(LeetCode Algorithm Problem)

Rotate Image 本题的要求是将一幅n*n的正方形图片顺时针旋转90°,并且空间复杂度为O(1)。 原题链接You are given an n x n 2D matrix represe...

Rotate Image - LeetCode 48

题目描述: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw...

[LeetCode-Java]48. Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).解1...

Leetcode48. Rotate Image

题目You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise)....
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)