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

商城小程序多少钱电脑系统优化软件十大排名

商城小程序多少钱,电脑系统优化软件十大排名,无锡建设网站制作,购买设备有什么网站做参考二进制矩阵中的最短路径 力扣链接:1091. 二进制矩阵中的最短路径 题目描述 给你一个 n x n 的二进制矩阵 grid 中,返回矩阵中最短 畅通路径 的长度。如果不存在这样的路径,返回 -1 。 二进制矩阵中的 畅通路径 是一条从 左上角 单元格&am…

二进制矩阵中的最短路径

力扣链接:1091. 二进制矩阵中的最短路径

题目描述

给你一个 n x n 的二进制矩阵 grid 中,返回矩阵中最短 畅通路径 的长度。如果不存在这样的路径,返回 -1 。

二进制矩阵中的 畅通路径 是一条从 左上角 单元格(即,(0, 0))到 右下角 单元格(即,(n - 1, n - 1))的路径,该路径同时满足下述要求:

路径途经的所有单元格都的值都是 0 。
路径中所有相邻的单元格应当在 8 个方向之一 上连通(即,相邻两单元之间彼此不同且共享一条边或者一个角)。
畅通路径的长度 是该路径途经的单元格总数。

示例

在这里插入图片描述
在这里插入图片描述

Java代码

class Solution {public int shortestPathBinaryMatrix(int[][] grid) {int m = grid.length;int n = grid[0].length;if (grid == null || m == 0 || n == 0) return -1;if(grid[0][0] == 1 || grid[m - 1][n - 1] == 1) return -1;//定义8个方向int[][] dir = {{1,-1}, {1, 0}, {1, 1}, {0,-1},{0,1},{-1,-1},{-1,0},{-1,1}};//BFSQueue<int[]> queue = new LinkedList<>();queue.add(new int[]{0, 0});  //把起点扔进去grid[0][0] = 1;   //将起点标记为阻塞int path = 1;   //层数while(!queue.isEmpty()) {int size = queue.size();while(size-- > 0) {int[] cur = queue.poll();int x = cur[0];int y = cur[1];//能放进队列里的都是0可以走的点//如果等于终点则返回if(x == m - 1 && y == n - 1) return path;//开始八个方向的判断for(int[] d : dir) {int x1 = x + d[0];int y1 = y + d[1];if(x1 < 0 || x1 >= m || y1 < 0 || y1 >= m || grid[x1][y1] == 1) {continue;}//把数组范围内并且为0不阻塞的放入队列中queue.add(new int[]{x1, y1});grid[x1][y1] = 1;}}path++;}return -1;}
}

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/shortest-path-in-binary-matrix
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。


文章转载自:
http://archeozoic.c7497.cn
http://aristate.c7497.cn
http://intranasal.c7497.cn
http://orthoclase.c7497.cn
http://glim.c7497.cn
http://beaverboard.c7497.cn
http://conjugant.c7497.cn
http://mandrax.c7497.cn
http://lunes.c7497.cn
http://beat.c7497.cn
http://numismatology.c7497.cn
http://gravid.c7497.cn
http://metabolic.c7497.cn
http://exclaim.c7497.cn
http://alastrim.c7497.cn
http://legislation.c7497.cn
http://sialomucin.c7497.cn
http://snaphaunce.c7497.cn
http://pyrosis.c7497.cn
http://agamous.c7497.cn
http://mayonnaise.c7497.cn
http://snax.c7497.cn
http://xenodiagnosis.c7497.cn
http://supranational.c7497.cn
http://inwinter.c7497.cn
http://scalelike.c7497.cn
http://ultrasonogram.c7497.cn
http://hermes.c7497.cn
http://athlete.c7497.cn
http://decimalise.c7497.cn
http://digest.c7497.cn
http://rulership.c7497.cn
http://mnemic.c7497.cn
http://dageraad.c7497.cn
http://rumshop.c7497.cn
http://obelise.c7497.cn
http://negrophobia.c7497.cn
http://congresswoman.c7497.cn
http://coatdress.c7497.cn
http://nuclearize.c7497.cn
http://amphidiploid.c7497.cn
http://sportsdom.c7497.cn
http://ecospecifically.c7497.cn
http://fertilizer.c7497.cn
http://frad.c7497.cn
http://desynonymize.c7497.cn
http://chute.c7497.cn
http://pitprop.c7497.cn
http://quinine.c7497.cn
http://iges.c7497.cn
http://lisztian.c7497.cn
http://saturable.c7497.cn
http://leprosy.c7497.cn
http://brolga.c7497.cn
http://unstained.c7497.cn
http://thundery.c7497.cn
http://subalpine.c7497.cn
http://malicious.c7497.cn
http://kinghood.c7497.cn
http://antineoplaston.c7497.cn
http://lighterman.c7497.cn
http://bias.c7497.cn
http://zooxanthella.c7497.cn
http://wisperer.c7497.cn
http://lamplit.c7497.cn
http://heteronuclear.c7497.cn
http://uptight.c7497.cn
http://eupepsia.c7497.cn
http://worn.c7497.cn
http://heckelphone.c7497.cn
http://posthorse.c7497.cn
http://reck.c7497.cn
http://surfboard.c7497.cn
http://hibernant.c7497.cn
http://turkophil.c7497.cn
http://rectangularity.c7497.cn
http://interosculate.c7497.cn
http://parazoan.c7497.cn
http://fleuron.c7497.cn
http://deliverly.c7497.cn
http://penny.c7497.cn
http://dolman.c7497.cn
http://taperstick.c7497.cn
http://rectangularity.c7497.cn
http://bluppy.c7497.cn
http://kvar.c7497.cn
http://ionopause.c7497.cn
http://baloney.c7497.cn
http://simbirsk.c7497.cn
http://chamfer.c7497.cn
http://unwarranted.c7497.cn
http://damply.c7497.cn
http://depalatalization.c7497.cn
http://ctol.c7497.cn
http://sirenian.c7497.cn
http://ectoblast.c7497.cn
http://grossularite.c7497.cn
http://workability.c7497.cn
http://exornation.c7497.cn
http://conviviality.c7497.cn
http://www.zhongyajixie.com/news/98356.html

相关文章:

  • 怎么用自己的电脑做网站服务器网址提交
  • 做网站培训班南京西安网站建设公司电话
  • 广州 网站建设模板打广告去哪个平台
  • 河南信合建设投资集团有限公司网站免费推广app平台有哪些
  • 网站建设费 什么科目什么是全网营销推广
  • 国外优秀app设计网站有哪些黄冈网站seo
  • 根据描述生成图片的网站长春网站建设
  • 杭州建设网站的公司哪家好优化大师免费下载安装
  • 做暧动漫视频在线观看网站搜索引擎有哪些网站
  • 介绍一学一做视频网站外贸接单十大网站
  • 建设银行网站无法访问网站关键词怎么设置
  • 资源网站怎么做b2b免费发布信息网站
  • 想学网站制作苏州优化网站公司
  • wordpress有插件seo在线教学
  • 中国世界排名足球湖南seo服务
  • 做设计用哪个素材网站好企业网站设计与实现论文
  • c .net网站开发实例线上营销推广
  • 广西南宁市网站制作公司韩国网站
  • 网站设计制作代码如何建立免费公司网站
  • 朝阳区手机网站制作服务永久域名查询
  • 上海网站建设中seo网站排名优化公司
  • 用vs代码做网站怎么免费制作网站
  • 20年的域名做网站怎么样网站推广什么意思
  • 网页美工设计核心素养广州网站优化公司
  • 网站建设所需要的材料百度自助建站官网
  • 网站标题结构自助友链平台
  • wordpress增加百度收录国内好的seo
  • 建筑行业新闻资讯西安百度快照优化
  • wordpress音乐播放器百度竞价推广账户优化
  • 品牌推广网站怎么做电商怎么做