题解 | 像素翻转

像素翻转

https://www.nowcoder.com/practice/17ab1e527c504df09a600e1af09d9a60

class Transform {
  public:
    vector<vector<int> > transformImage(vector<vector<int> > mat, int n) {
        // write code here
        //[1,2,3]   [7,4,1]
        //[4,5,6] =>[8,5,2]
        //[7,8,9]   [9,6,3]

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                swap(mat[i][j], mat[j][i]);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n/2; j++) {
                swap(mat[i][j], mat[i][n-j-1]);
            }
        }

        return mat;
    }
};

全部评论

相关推荐

notbeentak...:真的nc,算毕业6月份,要给这种b公司打半年多白工😅
点赞 评论 收藏
分享
10-10 16:30
济宁学院 Java
不想做程序员:面试官:蓝桥杯三等奖?你多去两次厕所都能拿二等吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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