LeetCode 048 Rotate Image
题目要求:Rotate Image
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?

代码如下:
class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
const int n = matrix.size();
for(int i = 0; i < n; i++) //沿着副对角线反转
for(int j = 0; j < n - i; j++)
swap(matrix[i][j], matrix[n - 1 - j][n - 1 - i]);
for(int i = 0; i < n / 2; i++)//沿着水平中线反转
for(int j = 0; j < n; j++)
swap(matrix[i][j], matrix[n - 1 - i][j]);
}
};
LeetCode 048 Rotate Image的更多相关文章
- [Leetcode][048] Rotate Image 略详细 (Java)
题目在这里 https://leetcode.com/problems/rotate-image/ [个人分析] 这个题目,我觉得就是考察基本功.考察细心的,算法方面没有太多东西,但是对于坐标的使用有 ...
- Java for LeetCode 048 Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- [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] 61. Rotate List 旋转链表
Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...
- 【LeetCode】048. Rotate Image
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- LeetCode 189. Rotate Array (旋转数组)
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- 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】 Rotate List 循环链表
题目:rotate list 解法1: <span style="font-size:18px;">/**LeetCode Rotate List:Given a li ...
随机推荐
- ValueError: Unknown label type: 'continuous'
说明:SVM训练的标签列必须为整型数值,不能为float.y = np.array(y, dtype=int)或y.astype('int')
- Java_多线程实现
一个类两个接口 Tread类: 使用时继承Thread类 Runnable接口: 使用时实现Runnable接口 Callable接口: 使用时实现Callable接口 由于类只能单继承, 接口可以多 ...
- c++11-17 模板核心知识(二)—— 类模板
类模板声明.实现与使用 Class Instantiation 使用类模板的部分成员函数 Concept 友元 方式一 方式二 类模板的全特化 类模板的偏特化 多模板参数的偏特化 默认模板参数 Typ ...
- PhpExcel PhpSpreadsheet 锁定单元格 正确做法!!
首先声明 PhpExcel 已经停止更新,转而代之的是 PhpSpreadsheet : 但是 !!不必担心 PhpSpreadsheet 包含了大部分的 PhpExcel 的功能 : //code ...
- Java字符串到数组的转换--最后放大招
本文是关于如何在Java中以不同方式将String转换为String Array的几种方法,按照惯例,文末会分享Groovy语言中的实现. split()方法 字符串api是通过split()方法添加 ...
- Javascript基础知识面试题
[]==![] 解题思路: step1, []==!Boolean([]);step2, []==!true;step3, []==false;step4, [].valueOf()= ...
- wait()系统调用分别演示在父子进程
废话不多说开代码 在父进程调用wait() #include<stdio.h> #include<unistd.h> #include<sys/wait.h> in ...
- MySQL索引结构之B+树索引(面)
首先要明白索引(index)是在存储引擎(storage engine)层面实现的,而不是server层面.不是所有的存储引擎都支持所有的索引类型.即使多个存储引擎支持某一索引类型,它们的实现和行为也 ...
- Mysql之存储过程与存储函数
1 存储过程 1.1 什么是存储过程 存储过程是一组为了完成某项特定功能的sql语句集,其实质上就是一段存储在数据库中的代码,他可以由声明式的sql语句(如CREATE,UPDATE,SELECT等语 ...
- 224、Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...