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). ...
随机推荐
- apache 中 ServerAlias让多个域名绑定到同一空间
在apache的虚拟主机中,如果书写了.ServerAlias www.a2.com www.a3.com这样的语句,就可以给虚拟主机增加多个域名,而且这些域名都访问同一个站点. #Listen 81 ...
- 计算概论(A)/基础编程练习1(8题)/5:鸡兔同笼
#include<stdio.h> int main() { // 鸡兔同笼中脚的总数:a < 32768 int a; scanf("%d", &a); ...
- 04: Mysql性能优化
MySQL其他篇 目录: 参考网站 1.1 Mysql数据库的优化技术 1.2 数据库表设计 1.3 SQL优化 1.为查询缓存优化你的查询 2.EXPLAIN 你的 SELECT 查询 3. 当只要 ...
- iotop监控磁盘动态安装
开始装iotp tar xvf iotop-0.3.1.tar.gz 用python安装(如果没有蟒蛇, yum一个吧) cd iotop-0.3.1 python setup.py build py ...
- 特征提取的综合实验(多种角度比较SIFT、SURF、BRISK、ORB算法)
代码:https://files.cnblogs.com/files/jsxyhelu/main.zip 一.基本概念: 特征点提取在“目标识别.图像拼接.运动跟踪.图像检索.自动定位”等研究中起着重 ...
- 车载项目问题解(memset)
1memset函数解 1.void *memset(void *s,int c,size_t n) 总的作用:将已开辟内存空间 s 的首 n 个字节的值设为值 c.2.例子 #includevoid ...
- List集合实现简易学生管理
题目: 代码: package org.wlgzs; import java.util.ArrayList; import java.util.List; import java.util.Scann ...
- Android 自动化测试介绍
1 介绍: 风格: 3, 4,
- linux 安装MySql 5.7.20
1.下载文件(https://pan.baidu.com/s/1c1VBcHy)放到目录:/usr/local/ 2.解压 cd /usr/local/ tar -zxvf mysql-5.7.20- ...
- 【第十一章】 springboot + mongodb(简单查询)
1.mongodb在mac上的安装 下载mongodb,https://www.mongodb.org/ 解压缩到一个指定文件夹,如:/Users/enniu1/Desktop/zjg/mongodb ...