lintcode-旋转图像-161
来源:互联网 发布:2016网络最新最火的词 编辑:程序博客网 时间:2024/05/19 13:14
给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像。
样例
给出一个矩形[[1,2],[3,4]],90度顺时针旋转后,返回[[3,1],[4,2]]
挑战
能否在原地完成?
常规解法:
class Solution {public: void rotate(vector<vector<int> > &matrix) { if(matrix.empty()) return ; const int row=matrix[0].size() ; const int cal=matrix.size(); int ret[row][cal]; for(int i=0;i<row;++i) for(int j=0;j<cal;++j){ ret[i][cal-j-1]=matrix[j][i]; } matrix.clear(); for(int i=0;i<row;++i){ vector<int> base; for(int j=0;j<cal;++j){ base.push_back(ret[i][j]); } matrix.push_back(base); } }};
0 0
- lintcode-旋转图像-161
- LintCode 161-旋转图像
- LintCode-旋转图像
- LintCode:旋转图像
- LintCode:旋转图像
- 旋转图像-LintCode
- [LintCode] 旋转图像 Rotate Image
- LintCode-旋转链表
- LintCode-旋转链表
- LintCode:旋转链表
- LintCode:旋转字符串
- lintcode ----旋转字符串
- Lintcode 恢复旋转数组
- LintCode 8 旋转字符串
- LintCode : 旋转链表
- Lintcode 旋转字符串
- LintCode 旋转字符串
- lintcode--旋转字符串
- Leetcode: Move Zeroes
- 从单链表中输出指定值的节点
- 【编程题】-C++实现:判断字符串在末尾加一个字符,能否构成回文串
- 一个小公司老板的日常管理,希望能让创业的朋友学到东西
- 网络编程入门(1
- lintcode-旋转图像-161
- Java命令行执行那些事
- 黑马程序员---C语言 内存分区
- 详解Objective-C的meta-class ,runtime创建类,添加实例变量
- Fiddler手机抓包
- lintcode-跳跃游戏-116
- 无锁编程(一) - Double-checked Locking
- git的学习--绪论
- 由jQuery到AngularJS的思维转变