当前位置:网站首页>Leetcode T48: rotating images
Leetcode T48: rotating images
2022-07-04 14:23:00 【Fan Qianzhi】
Title Description
Given a n × n Two dimensional matrix of matrix Represents an image . Please rotate the image clockwise 90 degree .
You must be there. In situ Rotated image , This means that you need to modify the input two-dimensional matrix directly . Please do not Use another matrix to rotate the image .
Example 1:

Input :matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output :[[7,4,1],[8,5,2],[9,6,3]]
Example 2:

Input :matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output :[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
Tips :
- n == matrix.length == matrix[i].length
- 1 <= n <= 20
- -1000 <= matrix[i][j] <= 1000
Ideas
rotate 90° Equal to first Transposition , Again Mirror symmetry .
Code
public void rotate(int[][] matrix) {
int n = matrix.length;
// Transposition
for(int i = 0; i < n; i++) {
for(int j = 0; j < i; j++) {
int t = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = t;
}
}
// Mirror symmetry
for(int i = 0; i < n; i++) {
for(int j = 0; j < n/2; j++) {
int t = matrix[i][j]; matrix[i][j] = matrix[i][n-1-j]; matrix[i][n-1-j] = t;
}
}
}
边栏推荐
猜你喜欢

Test evaluation of software testing

Chapter 17 process memory

潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)

2022 practice questions and mock exams for the main principals of hazardous chemical business units

Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT

按照功能对Boost库进行分类

Why should Base64 encoding be used for image transmission

数据仓库面试问题准备

Test process arrangement (3)

nowcoder重排链表
随机推荐
海外游戏代投需要注意的
Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
NowCoder 反转链表
数据仓库面试问题准备
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
GCC [6] - 4 stages of compilation
潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
Excel quickly merges multiple rows of data
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
Opencv3.2 and opencv2.4 installation
Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
统计php程序运行时间及设置PHP最长运行时间
Visual Studio调试方式详解
QT how to detect whether the mouse is on a control
R language dplyr package summary_ If function calculates the mean and median of all numerical data columns in dataframe data, and summarizes all numerical variables based on conditions
Idea shortcut keys
Learning projects are self-made, and growth opportunities are self created
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程