Rotate Image

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

LeetCode 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?


关键地方在于就地。而不用新的内存。
这里采用两次旋转的方法。

/*
 1 2 3     7 8 9     7 4 1
 4 5 6  => 4 5 6  => 8 5 2
 7 8 9     1 2 3     9 6 3
*/
void rotate(vector<vector<int> > &matrix) {
    reverse(matrix.begin(), matrix.end());
    for (int i = 0; i < matrix.size(); ++i) {
        for (int j = i + 1; j < matrix[i].size(); ++j)
            swap(matrix[i][j], matrix[j][i]);
    }
}

相关推荐

R语言使用magick包的image_rotate函数、image_flip函数、image_flop函数对图像进行缩放旋转、镜像、翻转(Rotate or mirror the image

R语言使用magick包的image_rotate函数、image_flip函数、image_flop函数对图像进行缩放旋转、镜像、翻转(Rotate or mirror the image

data+scenario+science+insight 1552

PIL Image 旋转 Rotate函数的坑和解决方案

PIL Image 旋转 Rotate函数的坑和解决方案PIL Image旋转的坑有坑的代码解决方案:用transpose来做旋转代码 PIL Image旋转的坑 想做图片的90,180,270度旋转,原本使用的PIL.Image.rotate,但发现出来的图片长宽没有进行相应调整,导致图片有黑边,以下是有坑的代码和解决方案 有坑的代码 from PIL import Image def rotate(img_path): image = Image.open(img_path) angl

Tornado_Liao的博客 1万+

R语言使用magick包的image_rotate函数、image_flip函数、image_flop函数对图像进行缩放旋转、镜像、翻转

R语言使用magick包的image_rotate函数、image_flip函数、image_flop函数对图像进行缩放旋转、镜像、翻转

statistics+insight+vista+power 546

[leetcode]Rotate Image

新博文地址:[leetcode]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?  我没有想到in-place的方法...

mc46790090的专栏 124

Rotate Image - LeetCode

目录 题目链接 注意点 解法 小结 题目链接 Rotate Image - LeetCode 注意点 不能开新的二维数组 解法 解法一:先以对角线为轴对调数字,在将每一行逆序即可。时间复杂度O(n^2) class Solution { public: v...

weixin_30594001的博客 140

python开发halcon视觉_Halcon中两种实现旋转的方法rotate_image和affine_trans_image

Halcon中实现旋转的方式由两种。一种是rotate_image,该方式实现简单,但只能绕中心旋转。二是affine_trans_image,该方式实现较复杂,但是可以实现绕任意位置的旋转。1 rotate_image*ImageImageRotate分别是输入和输出图像*Phi是输入的旋转度数*interpolation是内插方式,默认为'constant' rotate_image(Ima...

weixin_39754411的博客 1507

[LeetCode]48. Rotate Image

48. Rotate Image 一、题目 Problem Description: You are given an nxnn x nnxn 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT

KKKKKKOBE_24的博客 707

[Rotate Image48]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? Analysis: This is a classic

coder 进阶的专栏 820

LeetCode 48. Rotate Image 解题报告

LeetCode 48. 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?.示例Example 1: Input: 1 2 4

骆小坑的填坑之旅 910

Leetcode 48. Rotate Image (python+cpp)

Leetcode 48. Rotate Image题目解法:transpose and reverse 题目 解法:transpose and reverse 对于这种题目,我个人觉得知道一种最经典直观的解法就好了。先transpose再reverse by row,这是最直观也是容易理解的方法。顺便也学习了transpose操作其实这么简单,说实话之前都没有注意,这是个非常实用的东西。 python代码如下: class Solution: def rotate(self, matrix: Li

qq_37821701的博客 226

48. Rotate Image**

48. Rotate Image** https://leetcode.com/problems/rotate-image/ 题目描述 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the ima...

珍妮的选择的博客 230

【Halcon逆向工程】rotate_image算子的C++实现及加速

【代码】【Halcon逆向工程】rotate_image算子的C++实现及加速。

里脊肉教父的博客 891

rotate_image

write_image (ImagePart, 'bmp', 0, 'D:/图像文件/1231.bmp')*旋转中心是图片的中心,旋转方向是逆时针(特别注意旋转的方向!*第三个参数是旋转的角度,第四个参数是插值的方式,默认就这个。*第一个参数是需要旋转的图片,第二个参数是选之后的图片。

小小的博客 341

LeetCodeRotate Image — C/C++ 实现

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? void rotate(int** matrix,

~心有所依~ 的博客 395

LeetCode Rotate Image

LeetCode解题之Rotate Image 原题 将一个矩阵顺时针旋转90度。 注意点: 最好不要申请额外空间 样例: 输入: matrix = [[1, 2, 3], [8, 9, 4], [7, 6, 5]] 输出: [[7, 8, 1], [6, 9, ...

weixin_34321977的博客 93
上一篇: Gray Code
下一篇: 跟我一起学习VIM - The Life Changing Editor
FightForProgrammer
博客等级 码龄12年 239粉丝 75原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值