leetcode48~Rotate Image

2024-02-06 03:38
文章标签 image rotate leetcode48

本文主要是介绍leetcode48~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?

public class RotateImage {//先旋转最外面一层,再旋转里面的层  注意:四个角的不应该重复旋转,故应该最大为n-2public void rotate(int[][] matrix) {if(matrix==null || matrix.length<2) return;int n = matrix.length;for(int i=0;i<n-1;i++) {for(int j=i;j<n-1-i;j++) {//旋转90度,横坐标变为纵坐标int tmp = matrix[i][j];matrix[i][j] = matrix[n-1-j][i];matrix[n-1-j][i] = matrix[n-1-i][n-1-j];matrix[n-1-i][n-1-j] = matrix[j][n-1-i];matrix[j][n-1-i] = tmp;}}}//比较容易理解的做法//先对角线进行交换,然后第一列和最后一列交换,第二列和倒数第二列交换public void rotate2(int[][] matrix) {if(matrix==null || matrix.length<2) return;int n = matrix.length;//对角线交换for(int i=0;i<n;i++) {for(int j=i;j<n;j++) {int temp = 0;temp = matrix[i][j];matrix[i][j] = matrix[j][i];matrix[j][i] = temp;}}//列列交换for(int i =0 ; i<n; i++){for(int j = 0; j<n/2; j++){int temp = 0;temp = matrix[i][j];matrix[i][j] = matrix[i][matrix.length-1-j];matrix[i][matrix.length-1-j] = temp;}}}
}

这篇关于leetcode48~Rotate Image的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/683032

相关文章

1_Image和Matrix的使用

参考博文: https://www.cnblogs.com/bomo/archive/2013/03/28/2986573.html

【QML】用 Image(QQuickPaintedItem) 显示图片

大体功能: 频繁地往界面推送图片,帧率达到视频效果。捕获画布上的鼠标事件和键盘事件。 代码如下: // DrawImageInQQuickPaintedItem.pro 代码如下:QT += quick# You can make your code fail to compile if it uses deprecated APIs.# In order to do so, uncom

GIM: Learning Generalizable Image Matcher From Internet Videos

【引用格式】:Shen X, Yin W, Müller M, et al. GIM: Learning Generalizable Image Matcher From Internet Videos[C]//The Twelfth International Conference on Learning Representations. 2023. 【网址】:https://arxiv.or

U-Net for Image Segmentation

1.Unet for Image Segmentation 笔记来源:使用Pytorch搭建U-Net网络并基于DRIVE数据集训练(语义分割) 1.1 DoubleConv (Conv2d+BatchNorm2d+ReLU) import torchimport torch.nn as nnimport torch.nn.functional as F# nn.Sequential

微信小程序-获取swiper-item中image的值(item-id)

滑过一个图片获取该图片的id,或者打印其他的item值 只需要加:item-id="{{item.id}}" <swiper bindchange="swiperchange"><block wx:for="{{photos}}" wx:key='{{item.id}}'><swiper-item item-id="{{item.id}}"><image src='{{item.url}

PHPWord 又拍云图片导出被识别为 image/webp 无法导出的问题

1.解决办法读取图片转jpg 存储在windows 临时目录中,然后读取图片 if (!empty($v['goods_img'])) {foreach ($v['goods_img'] as $imgs) {if (!empty($imgs)) {$imageUrl = trim('http://cdn.wowo.com' . '/' . $imgs . '!/fh/100');$image

Android开发系列(五)Jetpack Compose之Icon Image

Icon是用于在界面上显示矢量图标的组件。它提供了很多内置的矢量图标,也支持自定义图标。要使用Icon组件,可以通过指定图标资源的名称或引用来创建一个Icon对象。例如,使用Icons.Default.Home来创建一个默认风格的首页图标。可以通过设置图标的大小、颜色、和点击事件等属性来自定义Icon的外观和行为。     Image是用于在界面上显示位图图像的组件。它支持从本地资源、网络

AIGC-CVPR2024best paper-Rich Human Feedback for Text-to-Image Generation-论文精读

Rich Human Feedback for Text-to-Image Generation斩获CVPR2024最佳论文!受大模型中的RLHF技术启发,团队用人类反馈来改进Stable Diffusion等文生图模型。这项研究来自UCSD、谷歌等。 在本文中,作者通过标记不可信或与文本不对齐的图像区域,以及注释文本提示中的哪些单词在图像上被歪曲或丢失来丰富反馈信号。 在 18K 生成图像 (R

UNSUPERVISED CROSS-DOMAIN IMAGE GENERATION

本文提出了一个域转换网络(domain transfer network,DTN),网络的作用是,对于给定两个域S,T,我们希望学习一个生成函数G,将S域的样本映射到域T,这样,对于一个给定函数f,不管f的输入为来自域S或T,f的输出会保持不变. 网络结构如下: 生成网络包括函数f,g.f用于提取输入图像的特征,得到一个特征向量.g的输入为f的输出,输出为目标风格的图像.训练数据为为无监督

el-image 增加图片下载和删除功能

<el-image@click.stop.prevent="clickImage"style="width: 100px; height: 100px":src="item":preview-src-list="[item]"></el-image> clickImage() {this.$nextTick(() =>