当前位置:网站首页>【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]
边栏推荐
- CNN优化trick
- Is it safe to open a new bond registration account? Is there any risk?
- 粒子滤波 PF——在机动目标跟踪中的应用(粒子滤波VS扩展卡尔曼滤波)
- Unity C # e-learning (IX) -- wwwfrom
- 反射修改final
- 1. accounting basis -- several major elements of accounting (general accounting theory, accounting subjects and accounts)
- Smoothing data using convolution
- 【C语言练习——打印空心上三角及其变形】
- el-dialog拖拽,边界问题完全修正,网上版本的bug修复
- There are so many vulnerabilities in tcp/ip protocol?
猜你喜欢

【ceph】CephFS 内部实现(二):示例--未消化

面试高频 | 你追我赶的Flink双流join

Evaluation - TOPSIS

在重新格式化时不要删除自定义换行符(Don‘t remove custom line breaks on reformat)
![[CEPH] Lock Notes of cephfs](/img/9a/b68e7b07b1187794c0dbed36eea749.png)
[CEPH] Lock Notes of cephfs

功能:crypto-js加密解密

【C语言练习——打印空心上三角及其变形】

【文件】VFS四大struct:file、dentry、inode、super_block 是什么?区别?关系?--编辑中

【SNMP】snmp trap 介绍、安装、命令|Trap的发送与接收代码实现

【小程序实战系列】小程序框架 页面注册 生命周期 介绍
随机推荐
# 粒子滤波 PF——三维匀速运动CV目标跟踪(粒子滤波VS扩展卡尔曼滤波)
2022 Beijing Shijingshan District specializes in the application process for special new small and medium-sized enterprises, with a subsidy of 100000-200000 yuan
Learning memory barrier
Applet: uniapp solves vendor JS is too large
【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
【SNMP】snmp trap 介绍、安装、命令|Trap的发送与接收代码实现
Unable to download Plug-in after idea local agent
评价——模糊综合评价
数据库-视图
北京房山区专精特新小巨人企业认定条件,补贴50万
【ceph】CephFS 内部实现(三):快照
Secure JSON protocol
shell脚本多进程并发写法实例(高阶修炼)
Use of abortcontroller
【ceph】mkdir|mksnap流程源码分析|锁状态切换实例
5张图诠释了容器网络
【TcaplusDB知识库】TcaplusDB常规单据介绍
[tcapulusdb knowledge base] Introduction to tcapulusdb data structure
Is it safe to buy stocks and open accounts through the QR code of the securities manager? Want to open an account for stock trading
【ceph】cephfs的锁 笔记