题解 | #顺时针旋转矩阵#

顺时针旋转矩阵

http://www.nowcoder.com/practice/2e95333fbdd4451395066957e24909cc


public class Solution {
    public int[][] rotateMatrix(int[][] mat, int n) {
        // write code here
        //mat[i][j]旋转到mat[j][n-i-1]的位置
        int[][] temp = new int[n][n];
        for(int i = 0;i<n;i++){
            for(int j = 0;j< n;j++){
                temp[j][n-1-i] = mat[i][j];
            }
        }
        return temp;
    }
}
全部评论

相关推荐

牛客鼠:校友你这简历基本无敌了,春招刷刷题去冲大厂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客企业服务