LeetCode OJ--Rotate Image
http://oj.leetcode.com/problems/rotate-image/
将矩阵顺时针旋转90度。要求为原地算法。
注意对输入的测试,矩阵为空,长度为1,为2时……
#include <iostream>
#include <vector>
using namespace std; class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
if(matrix.empty())
return;
vector<vector<int> >matrixB;
vector<int> onePiece; int len = matrix[].size();
if(len<=)
{
return;
}
for(int j = ;j<len;j++)
{
onePiece.clear();
for(int i = ;i<len;i++)
{
onePiece.push_back(matrix[len--i][j]);
}
matrixB.push_back(onePiece);
}
matrix = matrixB;
}
}; int main()
{
Solution myS;
vector<vector<int> > matrix;
vector<int> onePiece;
onePiece.clear();
onePiece.push_back();
matrix.push_back(onePiece);
/*onePiece.push_back(2);
onePiece.push_back(5);
matrix.push_back(onePiece);
onePiece.clear();
onePiece.push_back(3);
onePiece.push_back(4);
onePiece.push_back(6);
matrix.push_back(onePiece); onePiece.clear();
onePiece.push_back(8);
onePiece.push_back(9);
onePiece.push_back(10);*/
//matrix.push_back(onePiece); myS.rotate(matrix);
return ;
}
原地算法如下:
LeetCode OJ--Rotate Image的更多相关文章
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ学习
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...
- LeetCode OJ 297. Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
- LeetCode OJ 之 Maximal Square (最大的正方形)
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...
- LeetCode OJ:Integer to Roman(转换整数到罗马字符)
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- LeetCode OJ:Serialize and Deserialize Binary Tree(对树序列化以及解序列化)
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
随机推荐
- python--字符编码理解
一.字符编码简史: 美国:1963年 ASCII (包含127个字符 占1个字节) 中国:1980年 GB2312 (收录7445个汉字,包括6763个汉字和682个其它符号) 1993年 GB13 ...
- 图解Disruptor框架(一):初识Ringbuffer
图解Disruptor框架(一):初识Ringbuffer 概述 1. 什么是Disruptor?为什么是Disruptor? Disruptor是一个性能十分强悍的无锁高并发框架.在JUC并发包中, ...
- 实验4 —— [bx]和loop的使用
实验 综合使用 loop.[bx],编写完整汇编程序,实现向内存 b800:07b8 开始的连续 16 个字单元重复填充字数据 0403H. 以下为示例程序: assume cs:code # 1 c ...
- AOP面向切面编程笔记
1.AOP概念:Aspect Oriented Programming 面向切面编程 2.作用:本质上来说是一种简化代码的方式 继承机制 封装方法 动态代理 …… 3.情景举例 ①数学计算器接口[Ma ...
- LeetCode(200) Number of Islands
题目 Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is su ...
- MIP启发式算法:Variable Neighborhood Decomposition Search
*本文记录和分享学习到的知识,算不上原创. *参考文献见链接. 本文主要简述和VND VNS RINS很相关的vairable neighborhood decomposition search. 目 ...
- PHP-redis命令之 列表(lists)
三.列表(lists) 1.lpush:将所有指定的值插入到存于 key 的列表的头部.如果 key 不存在,那么在进行 push 操作前会创建一个空列表. 如果 key 对应的值不是一个 list ...
- Python之多线程与多进程(一)
多线程 多线程是程序在同样的上下文中同时运行多条线程的能力.这些线程共享同一个进程的资源,可以在并发模式(单核处理器)或并行模式(多核处理器)下执行多个任务 多线程有以下几个优点: 持续响应:在单线程 ...
- 光学字符识别OCR-3
连通性 可以看到,每一层的图像是由若干连通区域组成的,文字本身是由笔画较为密集组成的,因此往往文字也能够组成一个连通区域.这里的连通定义为 8邻接,即某个像素周围的8个像素都定义为邻接像素,邻接的像素 ...
- Jmeter测试https协议