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

顺时针旋转矩阵

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

using System;
using System.Collections.Generic;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param mat int整型二维数组
     * @param n int整型
     * @return int整型二维数组
     */
    public List<List<int>> rotateMatrix (List<List<int>> mat, int n) {
        // write code here
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int nTmp = mat[i][j];
                mat[i][j] = mat[j][i];
                mat[j][i] = nTmp;
            }
        }
        for (int i = 0; i < n; i++)
            mat[i].Reverse();
        return mat;
    }
}

全部评论

相关推荐

05-19 15:21
已编辑
门头沟学院 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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