题解 | #java实现#

顺时针旋转矩阵

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

import java.util.*;

public class Solution {
    public int[][] rotateMatrix(int[][] mat, int n) {
        // write code here
        int row = mat.length;
        int col = mat[0].length;
        
        int[][] res = new int[mat.length][mat[0].length];
        
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                res[i][j] = mat[row - 1 - j][i];
            }
        }
        
        return res;
    }
}

全部评论

相关推荐

10-17 17:54
门头沟学院 Java
点赞 评论 收藏
分享
代码飞升:别这样贬低自己,降低预期,放平心态,跟昨天的自己比。做好自己,反而会效率更高心态更好,加油兄弟
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务