LeetCode 48. Rotate Image My Submissions Question (矩阵旋转)
题目大意:给一个矩阵,将其按顺时针旋转90°。
题目分析:通法是先将矩阵转置,然后再反转每一行,或者是先反转每一列,然后再将其转置。I just want to say"It's amazing!".(forgivig my poor English!)
代码如下(代码怎么写已经不重要了!):
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int r=matrix.size();
int c=matrix[0].size();
for(int i=0;i<r;++i){
for(int j=i+1;j<c;++j)
swap(matrix[i][j],matrix[j][i]);
for(int j=0,k=c-1;j<k;++j,--k)
swap(matrix[i][j],matrix[i][k]);
}
}
};
LeetCode 48. Rotate Image My Submissions Question (矩阵旋转)的更多相关文章
- [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 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48 Rotate Image(2D图像旋转问题)
题目链接: https://leetcode.com/problems/rotate-image/?tab=Description Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode 48. Rotate Image (C++)
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- 【刷题笔记】LeetCode 48. Rotate Image
题意 原地顺时针翻转一个 n*n 的矩阵 图解 下面例子中用 5*5 矩阵做示例,如下图,我们要把该矩阵顺时针翻转90度,并且不能使用另外的矩阵空间来暂存数据,而是原地改变矩阵中数值. 我的想法是这样 ...
- [leetcode 48] rotate image
1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...
- leetCode 48.Rotate Image (旋转图像) 解题思路和方法
Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...
- [leetcode]48. Rotate Image旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
随机推荐
- sql server 数据排名
城市排名列表 )) AS px, ) pm25, ) pm10, ) co, ) no2, ) so2,) o3_8,) indexs,) aqi FROM monitor_city_hour m,c ...
- Python入门之Python中的logging模块
基本用法 下面的代码展示了logging最基本的用法. import logging import sys # 获取logger实例,如果参数为空则返回root logger logger = log ...
- django multidb --- router
之前一篇随笔, 提到了django中怎么使用多数据库, 但是在实际工程中遇到了一个问题,就是admin指定了使用某库, 在测试环境上没问题, 当部署后(库也变动了位置), 修改一个admin的mode ...
- 在ubuntu英文系统下使用中文输入法
How to install and use Chinese Input Method in the English Locale in Ubuntu ?(1) Check if there exis ...
- 20145330 《网络对抗》 Web安全基础实践
20145330 <网络对抗> Web安全基础实践 1.实验后回答问题 (1)SQL注入攻击原理,如何防御 SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字 ...
- SQLSERVER 数据从一张那个表复制到另一张表
insert into 表名1 ( 字段A ,字段B ,字段C) SELECT 字段A ,字段B ,字段C FROM 表名2 (where条件看情况而定)
- 自己写操作系统---bootsector篇
其实博主本来想在寒假自己写一个OSkernal的,高高兴兴的影印了本<一个操作系统的实现>. 然后又去图书馆借来<30天自制操作系统>和<X86/X64体系探索编程> ...
- The equation (扩展欧几里得)题解
There is an equation ax + by + c = 0. Given a,b,c,x1,x2,y1,y2 you must determine, how many integer r ...
- 风景区的面积及道路状况分析问题 test
参考文献: https://wenku.baidu.com/view/b6aed86baf1ffc4ffe47ac92.html #include <bits/stdc++.h> us ...
- AlexNet网络结构特点总结
参考论文:ImageNet Classification with Deep Convolutional Neural Networks 1.特点 1.1 ReLU Nonlinearity的提出 Re ...