当前位置: 首页 > news >正文

网站如何做分站系统南京seo优化

网站如何做分站系统,南京seo优化,wordpress框架简介,做网站运营用什么软件LeetCode:48. 旋转图像 受到力扣hot100:54. 螺旋矩阵的启发,我们可以对旋转图像按层旋转,我们只需要记录四个顶点,并且本题是一个方阵,四个顶点就能完成图像的旋转操作。 1、逐层旋转 注意到&#xff0…

LeetCode:48. 旋转图像
在这里插入图片描述

受到力扣hot100:54. 螺旋矩阵的启发,我们可以对旋转图像按层旋转,我们只需要记录四个顶点,并且本题是一个方阵,四个顶点就能完成图像的旋转操作。

1、逐层旋转

注意到,一层的四个顶点存在一定的位置关系,我们只需要记录四个值:
top_rowbottom_rowleft_colright_col,则上右下左四个顶点分别为:

  • (top_row,left_col)、(top_row,right_col)、(bottom_row,right_col)、(bottom_row,left_col)

当我们需要更新层时,注意矩阵的下标,只需进行如下操作:

  • top_row++
  • bottom_row--
  • left_col++
  • right_col--

这样我们就找到了一层的四个顶点,以及更新层的操作。

现在我们只需要逐层更新即可。
时间复杂度: O ( n 2 ) O(n^2) O(n2)
空间复杂度: O ( 1 ) O(1) O(1)

在这里插入图片描述

class Solution {
public:void rotate(vector<vector<int>>& matrix) {int top_row = 0, left_col = 0;int bottom_row = matrix.size() - 1, right_col = matrix.size() - 1;//由于size() > 1,所以可以这样做while(top_row < bottom_row){//方阵,结束条件int step = right_col - left_col;for(int i = 0; i < step; ++ i){int temp;//上换到右temp = matrix[top_row + i][right_col];matrix[top_row + i][right_col] = matrix[top_row][left_col + i];//右换到下int temp2 = temp;temp = matrix[bottom_row][right_col - i];matrix[bottom_row][right_col - i] = temp2;//下换到左temp2 = temp;temp = matrix[bottom_row - i][left_col];matrix[bottom_row - i][left_col] = temp2;//左换到上matrix[top_row][left_col + i] = temp;}//更新层top_row++;bottom_row--;left_col++;right_col--;}return ;}
};
  • 我们需要注意一个问题,判断结束条件时,由于方阵行数是n可以是偶数也可以是奇数,奇数时,上行和下行相等则结束。但如果是偶数时,他俩会交叉,因此是下行大于上行时结束!
    • 为了在编程时忽略奇偶数的这个问题,我们可以编程时将判断条件更宽泛
    • 如果top_row > bottom_row也不满足条件,那不要写top_row == bottom_row,而是将两者结合起来写,这样可以避免自己的遗漏。

为了节省临时变量,我们也可以按左下转到左上,右下转到左下,右上转到右下,左上转到右上的顺序旋转,这样只需要存储左上的值即可。

class Solution {
public:void rotate(vector<vector<int>>& matrix) {int top_row = 0, left_col = 0;int bottom_row = matrix.size() - 1, right_col = matrix.size() - 1;//由于size() > 1,所以可以这样做while(top_row < bottom_row){//方阵,结束条件int step = right_col - left_col;for(int i = 0; i < step; ++ i){int temp = matrix[top_row][left_col + i];matrix[top_row][left_col + i] = matrix[bottom_row - i][left_col];左换到上matrix[bottom_row - i][left_col] = matrix[bottom_row][right_col - i];//下换到左matrix[bottom_row][right_col - i] = matrix[top_row + i][right_col];//右换到下matrix[top_row + i][right_col] = temp;//上换到右}//更新层top_row++;bottom_row--;left_col++;right_col--;}return ;}
};

和官解的方法二类似。

2、两次翻转等于旋转

在这里插入图片描述

class Solution {
public:void rotate(vector<vector<int>>& matrix) {int n = matrix.size();// 水平翻转for (int i = 0; i < n / 2; ++i) {for (int j = 0; j < n; ++j) {swap(matrix[i][j], matrix[n - i - 1][j]);}}// 主对角线翻转for (int i = 0; i < n; ++i) {for (int j = 0; j < i; ++j) {swap(matrix[i][j], matrix[j][i]);}}}
};
http://www.dinnco.com/news/4025.html

相关文章:

  • 做淘宝任务赚钱的网站优化大师的优化项目有哪7个
  • 上海闵行区网站制作公司东莞今天的最新通知
  • wordpress插件 忍者弹窗天津seo建站
  • dnf交易网站建设广告公司推广软文
  • 织梦建站教程产品网络营销策划
  • 网站资源做缓存海外aso优化
  • phpwind做的网站竞价防恶意点击
  • 火是用什么做的视频网站二级域名注册
  • 怎么把自己做的网站发布出去黄页88网站推广效果
  • 做视频在哪个网站找素材西安网站推广排名
  • 网站建设企业文化驾校推广网络营销方案
  • 外贸建站是什么意思指数基金定投怎么买
  • 贵阳网站制作公司seo课程总结
  • 那个网站是专门做机械设备小程序如何推广运营
  • 用手机可以做网站吗多合一seo插件破解版
  • 动态ip做网站可以备案吗百度识图查图片
  • 网站建设费用是多少搜索引擎营销优化的方法
  • b2b模式举例河南平价的seo整站优化定制
  • 住建部网站建设部上海搜索优化推广
  • 做一级域名网站多少钱搜一搜排名点击软件
  • 美食怎么做的小视频网站济南seo网站排名关键词优化
  • SEO做得最好的网站互联网营销课程体系
  • PK10如何自己做网站长沙百度首页优化排名
  • 门户网站制作平台网站竞价推广都有哪些
  • 网站做优化每天一定要更新上海外贸seo
  • 做网站 客户大概会有那些问题发表文章的平台有哪些
  • 阿里巴巴网站怎么做推广方案seo谷歌
  • 口碑好的网站建设平台seo推广教程视频
  • 香港虚拟主机免费网站seo诊断分析
  • 查看网站架构推广策略怎么写