题目来源:
https://leetcode.com/problems/unique-paths-iii/
自我感觉难度/真实难度:
题意:
分析:

回溯法,直接DFS就可以了

自己的代码:
class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
res=0
n=len(grid)
m=len(grid[0])
for i in range(n):
for j in range(m):
if grid[i][j]==1:
start_i,start_j=i,j
if grid[i][j]==2:
end_i,end_j=i,j
def dfs(grid,k,l):
if grid[k][l]==-1:
return
if grid[k][l]==2:
for i in range(n):
for j in range(m):
if grid[n][m]==0:
return
res+=1
return
grid[k][l]=-1
left,right,up,down=l-1,l+1,k-1,k+1
if left>=0:
dfs(grid,k,left)
if right<=m:
dfs(grid,k,right)
if up>=0:
dfs(grid,up,l)
if down<=n:
dfs(grid,down,l)
dfs(grid,start_i,start_j)
return res
代码效率/结果:

虽然有思路,但是写出来的代码细节通不过,注意退回去的时候

优秀代码:
代码效率/结果:
自己优化后的代码:
反思改进策略:

1.函数输入变量设计的时候,我们要的是输入每次不同的东西。如果是全局的东西,我们可以不当作输入变量

2.回溯法,如果需要改变全局变量的值,那么从DFS后面回去的时候,要改回来!!!

写题时间时长:

980. Unique Paths III的更多相关文章

  1. LC 980. Unique Paths III

    On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square.  There is e ...

  2. 原题链接在这里:980. Unique Paths III

    原题链接在这里:https://leetcode.com/problems/unique-paths-iii/ 题目: On a 2-dimensional grid, there are 4 typ ...

  3. leetcode 980. Unique Paths III

    On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square.  There is e ...

  4. 【leetcode】980. Unique Paths III

    题目如下: On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square.  Ther ...

  5. 【LeetCode】980. Unique Paths III解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  6. Leetcode之深度优先搜索&回溯专题-980. 不同路径 III(Unique Paths III)

    Leetcode之深度优先搜索&回溯专题-980. 不同路径 III(Unique Paths III) 深度优先搜索的解题详细介绍,点击 在二维网格 grid 上,有 4 种类型的方格: 1 ...

  7. [Swift]LeetCode980. 不同路径 III | Unique Paths III

    On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square.  There is e ...

  8. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  9. [LeetCode] 63. Unique Paths II 不同的路径之二

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

随机推荐

  1. 使用HttpGet协议与正则表达实现桌面版的糗事百科

    写在前面 最近在重温asp.net,找了一本相关的书籍.本书在第一章就讲了,在不使用浏览器的情况下生成一个web请求,获取服务器返回的内容.于是在网上搜索关于Http请求相关的资料,发现了很多资料都是 ...

  2. 基于express+mongodb+pug的博客系统——后台篇

    上一篇介绍了模板引擎pug.js的用法,这一篇就主要写后台逻辑了. 后台的大部分的功能都有了,只是在已经登录的状态下,前台和后台的逻辑处理还不是很完善. 先上几张图吧,仿旧版的简书,改了下UI,因为没 ...

  3. bootstrap学习笔记(表单)

    1.基础表单 :对于基础表单,Bootstrap并未对其做太多的定制性效果设计,仅仅对表单内的fieldset.legend.label标签进行了定制. fieldset { min-width: 0 ...

  4. Visualizing CNN Layer in Keras

    CNN 权重可视化 How convolutional neural networks see the world An exploration of convnet filters with Ker ...

  5. Python 利用Python编写简单网络爬虫实例3

    利用Python编写简单网络爬虫实例3 by:授客 QQ:1033553122 实验环境 python版本:3.3.5(2.7下报错 实验目的 获取目标网站“http://bbs.51testing. ...

  6. Dlink DIR-823G 漏洞挖掘过程

    前言 本文由 本人 首发于 先知安全技术社区: https://xz.aliyun.com/u/5274 初步分析 首先下载固件 https://gitee.com/hac425/blog_data/ ...

  7. 润乾报表在proxool应用下的数据源配置

     大多数应用会使用proxool数据连接池,proxool.xml的配置文件如下: <?xml version="1.0″ encoding="UTF-8″?> & ...

  8. Android 进程回收

    1.Android 进程回收策略 众所周知,Android是基于Linux系统的.在Android进程回收策略中,Android进程与Linux进程根据OOM_ADJ阈值进行区分: OOM_ADJ & ...

  9. spring测试框架的使用

    junit的使用 1.加入 junit jar包 <dependency> <groupId>junit</groupId> <artifactId>j ...

  10. centos7 部署 汉化版 gitlab 10.0.2

    更新说明: 20171009:增加3.5的内容 20171008:整理出gitlab部署手册 =============================================== gitla ...