161-旋转图像

给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像。

样例

给出一个矩形[[1,2],[3,4]],90度顺时针旋转后,返回[[3,1],[4,2]]

挑战

能否在原地完成?

标签

Cracking The Coding Interview 矩阵

思路

先上下交换矩阵行,然后沿主对角线交换矩阵元素

code

class Solution {
public:
/*
* @param matrix: a lists of integers
* @return:
*/ void rotate(vector<vector<int>>& matrix) {
// write your code here
int size = matrix.size(), i = 0, j = 0;
if (size <= 0) {
return;
} for (i = 0; i < size / 2; i++) {
swap(matrix[i], matrix[size - 1 - i]);
}
for (i = 0; i < size; i++) {
for (j = 0; j < i; j++) {
swap(matrix[i][j], matrix[j][i]);
}
}
}
};

最新文章

  1. plsql11.06注册码
  2. 进fastreboot
  3. u3d单词学习plane
  4. Linux的加密认证功能以及openssl详解
  5. 【转】NSString属性什么时候用copy,什么时候用strong?
  6. EMVTag系列13《脱机PIN》
  7. [AngularJS] ngCloak
  8. oracle_修改Oracle数据库字符集 AL32UTF8;
  9. DotNetCore跨平台~Dockerfile的解释
  10. babel分析
  11. JS基础学习1
  12. MySQL 登陆
  13. Android SDK Manager无法更新的解决方案
  14. Centos7编译hadoop异常:Received fatal alert: handshake_failure
  15. Android dimen
  16. Remote Desktop Connection没法全屏解决方案
  17. 前端工程化 - gulp
  18. modelsim 仿真xilinx fir ip
  19. (剑指Offer)面试题41:和为s的两个数字
  20. node的express中间件之directory

热门文章

  1. MVC Controller 基类 BaseController 中的 Request
  2. Java : Spring基础 IOC
  3. YII2集成GOAOP,实现面向方面编程!
  4. Set的源码分析
  5. 第6天 Java基础语法
  6. LeetCode初级算法的Python实现--字符串
  7. 20145207 ms11_050漏洞攻击
  8. HardcodedDebugMode
  9. 解决replace格式替换后光标定位问题
  10. 「日常训练&amp;知识学习」单调栈