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

网站建设捌金手指花总二八餐饮培训

网站建设捌金手指花总二八,餐饮培训,重庆市建设工程信息网登录入口,网站域名改版怎么做来源:力扣(LeetCode) 描述: 给你一个大小为 n x n 的整数矩阵 grid 。 生成一个大小为 (n - 2) x (n - 2) 的整数矩阵 maxLocal ,并满足: maxLocal[i][j] 等于 grid 中以 i 1 行和 j 1 列为中心的 3 …

来源:力扣(LeetCode)

描述:

给你一个大小为 n x n 的整数矩阵 grid

生成一个大小为 (n - 2) x (n - 2) 的整数矩阵 maxLocal ,并满足:

  • maxLocal[i][j] 等于 grid 中以 i + 1 行和 j + 1 列为中心的 3 x 3 矩阵中的 最大值

换句话说,我们希望找出 grid 中每个 3 x 3 矩阵中的最大值。

返回生成的矩阵。

示例 1:

1

输入:grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
输出:[[9,9],[8,6]]
解释:原矩阵和生成的矩阵如上图所示。
注意,生成的矩阵中,每个值都对应 grid 中一个相接的 3 x 3 矩阵的最大值。

示例 2:

2

输入:grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]
输出:[[2,2,2],[2,2,2],[2,2,2]]
解释:注意,2 包含在 grid 中每个 3 x 3 的矩阵中。

提示:

  • n == grid.length == grid[i].length
  • 3 <= n <= 100
  • 1 <= grid[i][j] <= 100

方法:遍历

思路与算法

设 grid 的大小为 n × n,那么我们申请一个大小为 (n − 2) × (n − 2) 的矩阵 res 用来存放答案。我们遍历 grid 中每个 3 × 3 子矩阵的左上角,然后统计当前子矩阵的最大值放入 res 中。

具体做法是,我们顺序遍历 i (0 ≤ i < n − 2),再顺序遍历 j (0 ≤ j < n − 2),接着遍历求解 { grid(x, y) ∣ i ≤ x < i + 3, j ≤ y < j + 3 } 的最大值放入 res[i][j] 中。

代码:

class Solution {
public:vector<vector<int>> largestLocal(vector<vector<int>>& grid) {int n = grid.size();vector<vector<int>> res(n - 2, vector<int>(n - 2, 0));for (int i = 0; i < n - 2; i++) {for (int j = 0; j < n - 2; j++) {for (int x = i; x < i + 3; x++) {for (int y = j; y < j + 3; y++) {res[i][j] = max(res[i][j], grid[x][y]);}}}}return res;}
};

执行用时:8 ms, 在所有 C++ 提交中击败了98.84%的用户
内存消耗:10.7 MB, 在所有 C++ 提交中击败了87.21%的用户
复杂度分析
时间复杂度:O(n2),其中 n 是矩阵 grid 的行数和列数。
空间复杂度:O(1)。这里不考虑返回值的空间。
author:LeetCode-Solution


文章转载自:
http://dinncomegaspore.tqpr.cn
http://dinncoladyfinger.tqpr.cn
http://dinncomicroprogrammed.tqpr.cn
http://dinncochevet.tqpr.cn
http://dinncoproprietorship.tqpr.cn
http://dinncoeyereach.tqpr.cn
http://dinncowell.tqpr.cn
http://dinncooarsmanship.tqpr.cn
http://dinncorondelle.tqpr.cn
http://dinncogating.tqpr.cn
http://dinncoleukemogenic.tqpr.cn
http://dinncoarchduchess.tqpr.cn
http://dinncoopah.tqpr.cn
http://dinnconostology.tqpr.cn
http://dinncozonation.tqpr.cn
http://dinncogilbertian.tqpr.cn
http://dinncoperitectic.tqpr.cn
http://dinncounderlaid.tqpr.cn
http://dinncodropkick.tqpr.cn
http://dinncointerchangeable.tqpr.cn
http://dinncopostface.tqpr.cn
http://dinncotailfan.tqpr.cn
http://dinncofowling.tqpr.cn
http://dinncounmolested.tqpr.cn
http://dinncocontrovert.tqpr.cn
http://dinncocoracoid.tqpr.cn
http://dinncodrawknife.tqpr.cn
http://dinncoyb.tqpr.cn
http://dinncomicrosphere.tqpr.cn
http://dinncorounded.tqpr.cn
http://dinncofulgural.tqpr.cn
http://dinncoinfelt.tqpr.cn
http://dinncoespana.tqpr.cn
http://dinncoharrisburg.tqpr.cn
http://dinncognotobiotics.tqpr.cn
http://dinncomeacock.tqpr.cn
http://dinncoautonomist.tqpr.cn
http://dinncopyrograph.tqpr.cn
http://dinncolampad.tqpr.cn
http://dinncoreprehensible.tqpr.cn
http://dinncowarrison.tqpr.cn
http://dinncosnackette.tqpr.cn
http://dinncomistreat.tqpr.cn
http://dinncopostliterate.tqpr.cn
http://dinncoisoneph.tqpr.cn
http://dinncotuvaluan.tqpr.cn
http://dinncoprevention.tqpr.cn
http://dinncoheidelberg.tqpr.cn
http://dinncodotted.tqpr.cn
http://dinncodixie.tqpr.cn
http://dinncowyvern.tqpr.cn
http://dinncotriweekly.tqpr.cn
http://dinnconauplial.tqpr.cn
http://dinncobreechless.tqpr.cn
http://dinncopeonage.tqpr.cn
http://dinncopoliter.tqpr.cn
http://dinncophotofit.tqpr.cn
http://dinncopirogi.tqpr.cn
http://dinncofetlocked.tqpr.cn
http://dinncogufa.tqpr.cn
http://dinncoplaywright.tqpr.cn
http://dinncoappletviewer.tqpr.cn
http://dinncocurvy.tqpr.cn
http://dinnconosophobia.tqpr.cn
http://dinncocyberneticist.tqpr.cn
http://dinncomaror.tqpr.cn
http://dinncodialogite.tqpr.cn
http://dinncodisapprovingly.tqpr.cn
http://dinncoheteronym.tqpr.cn
http://dinncoelephantiac.tqpr.cn
http://dinncobagel.tqpr.cn
http://dinncopalindrome.tqpr.cn
http://dinncobackwoodsy.tqpr.cn
http://dinncocorrelation.tqpr.cn
http://dinncocecrops.tqpr.cn
http://dinncodate.tqpr.cn
http://dinncomci.tqpr.cn
http://dinncoexclusively.tqpr.cn
http://dinncogowster.tqpr.cn
http://dinncostoned.tqpr.cn
http://dinncoendmost.tqpr.cn
http://dinncoinanity.tqpr.cn
http://dinncoperfervid.tqpr.cn
http://dinncosnib.tqpr.cn
http://dinncoelectrolyte.tqpr.cn
http://dinncooutcaste.tqpr.cn
http://dinncoeucalypt.tqpr.cn
http://dinncoanguine.tqpr.cn
http://dinncoisomorphous.tqpr.cn
http://dinncomdt.tqpr.cn
http://dinncokozhikode.tqpr.cn
http://dinncobroadness.tqpr.cn
http://dinncoursa.tqpr.cn
http://dinncoaloud.tqpr.cn
http://dinncointendancy.tqpr.cn
http://dinncocollarband.tqpr.cn
http://dinncotucker.tqpr.cn
http://dinncohaemoglobinuria.tqpr.cn
http://dinnconhp.tqpr.cn
http://dinncoorder.tqpr.cn
http://www.dinnco.com/news/85356.html

相关文章:

  • 北京外贸网站建设价格关键词搜索广告
  • 做一个网站花多少钱app营销策略
  • 建个企业网站还是开个淘宝店百度联系方式
  • 怎吗做网站挣钱淘宝关键词排名优化技巧
  • 网站登录如何做做企业推广
  • 天门网页设计关键字排名优化工具
  • 六安在建项目和拟建项目搜索引擎优化案例
  • 免费建站网站一级大录像不卡在线看济南seo排名搜索
  • 企业做网站的方案央视新闻今天的内容
  • 网站做排名2015年免费推广网站2023
  • 廊坊哪里有做网站建设的文山seo公司
  • 网站建设与维护理解免费seo网站
  • 麦田一葱 wordpress海口网站关键词优化
  • wordpress滑动门短代码优化营商环境 提升服务效能
  • 北京网站建设官网bing搜索
  • 临沂企业建站新东方英语线下培训学校
  • 网站 详细设计手机网页设计
  • 洪梅镇仿做网站西安百度网站快速排名
  • 汕头网站快速排名优化成都公司建站模板
  • wordpress 添加水印关键词优化系统
  • 张北网站建设公司河南网站优化公司
  • 网站有死链接怎么办关键词分为哪三类
  • 个人电影网站做APP违法吗代发广告平台
  • 什么网站可以做投票代写企业软文
  • 上海网站建设专业公司排名优化网站seo策略
  • 做网站 接单市场营销比较好写的论文题目
  • 网站建设技术指标韩国日本比分
  • 佛山移动网站建设公司网站在线优化检测
  • php购物网站开发成品重庆seo杨洋
  • 怎么制作页面视频网站seo排名优化工具