当前位置:网站首页>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;
}
}
}
边栏推荐
- Why should Base64 encoding be used for image transmission
- 卷积神经网络经典论文集合(深度学习分类篇)
- MATLAB中tiledlayout函数使用
- 去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]
- flink sql-client.sh 使用教程
- ARouter的使用
- QT how to detect whether the mouse is on a control
- Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
- 如何游戏出海代运营、游戏出海代投
- Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
猜你喜欢
Understand chisel language thoroughly 12. Chisel project construction, operation and testing (IV) -- chisel test of chisel test
Leetcode T48:旋转图像
为什么图片传输要使用base64编码
第十七章 进程内存
Data warehouse interview question preparation
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
Ruiji takeout notes
使用CLion编译OGLPG-9th-Edition源码
gin集成支付宝支付
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
随机推荐
R语言dplyr包summarise_if函数计算dataframe数据中所有数值数据列的均值和中位数、基于条件进行数据汇总分析(Summarize all Numeric Variables)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Leetcode 61: 旋转链表
GCC【6】- 编译的4个阶段
How to package QT and share exe
失败率高达80%,企业数字化转型路上有哪些挑战?
Chapter 17 process memory
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
TestSuite and testrunner in unittest
Code hoof collection of wonderful secret place
Intelligence d'affaires bi analyse financière, analyse financière au sens étroit et analyse financière au sens large sont - ils différents?
架构方面的进步
2022 practice questions and mock exams for the main principals of hazardous chemical business units
为什么图片传输要使用base64编码
Excel快速合并多行数据
PHP log debugging
redis 日常笔记
R language uses the mutation function of dplyr package to standardize the specified data column (using mean function and SD function), and calculates the grouping mean of the standardized target varia
R language uses follow up of epidisplay package The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The col parameter specifies the
MATLAB中tiledlayout函数使用