当前位置:网站首页>【leetcode】48. Rotate image
【leetcode】48. Rotate image
2022-06-26 15:37:00 【liiiiiiiiiiiiike】
For details, please refer to 48. Rotated image
Their thinking :
- Rotate the image in place , You cannot use another matrix to rotate the image
- First flip the image horizontally , The first line and the last line exchange , The second line and the last line exchange , By analogy
- Next flip diagonally
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
""" Do not return anything, modify matrix in-place instead. """
# Rotate the image in place 90 degree , Do not use another matrix to rotate the image
# Double pointer
n = len(matrix)
# Flip horizontal
for i in range(n): # 0
left, right =0, n-1
while left <= right:
matrix[left][i], matrix[right][i] = matrix[right][i], matrix[left][i]
left += 1
right -= 1
# Turn diagonally
for i in range(n):
for j in range(i):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
Diagonal flip code !!!
for i in range(n):
for j in range(i):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
边栏推荐
- Vsomeip3 dual computer communication file configuration
- Applicable and inapplicable scenarios of mongodb series
- Ansible自动化的运用
- [tcapulusdb knowledge base] Introduction to tcapulusdb system management
- JS之简易deepCopy(简介递归)
- Restcloud ETL resolves shell script parameterization
- 【ceph】mkdir|mksnap流程源码分析|锁状态切换实例
- 10 minutes to understand bim+gis fusion, common BIM data formats and characteristics
- JS之事件
- 【微信小程序】事件绑定,你搞懂了吗?
猜你喜欢
【微信小程序】事件绑定,你搞懂了吗?
Don't remove custom line breaks on reformat
HR export data Excel VBA
How to handle 2gcsv files that cannot be opened? Use byzer
Keil4 opens the single-chip microcomputer project to a blank, and the problem of 100% program blocking of cpu4 is solved
Use of abortcontroller
[wechat applet] event binding, do you understand?
面试高频 | 你追我赶的Flink双流join
[applet practice series] Introduction to the registration life cycle of the applet framework page
数据库-视图
随机推荐
IDEA本地代理后,无法下载插件
安全Json协议
/etc/profile、/etc/bashrc、~/. Bashrc differences
MongoDB系列之适用场景和不适用场景
买股票通过券商经理的开户二维码开户资金是否安全?想开户炒股
Redis cluster
功能:crypto-js加密解密
# 粒子滤波 PF——三维匀速运动CV目标跟踪(粒子滤波VS扩展卡尔曼滤波)
[tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction
查词翻译类应用使用数据接口api总结
Restcloud ETL extracting dynamic library table data
效率超级加倍!pycharm十个小技巧就是这么神
[wechat applet] event binding, do you understand?
在重新格式化时不要删除自定义换行符(Don‘t remove custom line breaks on reformat)
北京房山区专精特新小巨人企业认定条件,补贴50万
[tcapulusdb knowledge base] Introduction to tcapulusdb system management
【TcaplusDB知识库】TcaplusDB运维单据介绍
10 minutes to understand bim+gis fusion, common BIM data formats and characteristics
【ceph】cephfs caps简介
[CEPH] cephfs internal implementation (IV): how is MDS started-- Undigested