首页 > TAG信息列表 > nextY

1091. 二进制矩阵中的最短路径(标准BFS)

1091. 二进制矩阵中的最短路径 给你一个 n x n 的二进制矩阵 grid 中,返回矩阵中最短 畅通路径 的长度。如果不存在这样的路径,返回 -1 。 二进制矩阵中的 畅通路径 是一条从 左上角 单元格(即,(0, 0))到 右下角 单元格(即,(n - 1, n - 1))的路径,该路径同时满足下述要求: 路

走迷宫——最短路径

问题:求从起点走到终点的最短路径 Java代码: 1 package com.lzp.maze.dfs; 2 3 import java.util.Scanner; 4 5 /** 6 * @author LZP 7 * @date 2021年4月3日 8 * @Description 9 * @version 1.0 10 * 11 * 求走迷宫的最短路径(从起点走到终点) 12 *

华为机试二星题--机器人走迷宫

题目 机器人走一个迷宫,给出迷宫的x和y(x*y的迷宫)并且迷宫中有障碍物,输入k表示障碍物有k个,并且会将障碍物的坐标挨个输入. 机器人从0,0的位置走到x,y的位置并且只能向x,y增加的方向走,不能回退. 如代码类注释展示的样子,#表示可以走的方格,0代表障碍,机器人从0,0的位置只

[LeetCode] 1091. Shortest Path in Binary Matrix

In an N by N square grid, each cell is either empty (0) or blocked (1). A clear path from top-left to bottom-right has length k if and only if it is composed of cells C_1, C_2, ..., C_k such that: Adjacent cells C_i and C_{i+1} are connected 8-dir

八皇后问题

八皇后问题 1 问题描述  在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列或同一斜线上,问一共有多少种摆法。 2 代码实现 递归回溯 def queens(num=8,state=()): def conflict(state,nextX): nextY=len(state) fo

0498. Diagonal Traverse (M)

Diagonal Traverse (M) 题目 Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Example: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,4,7,5,3,6,8,9] Exp