DFS算法

class Solution(object):def exist(self, board, word):""":type board: List[List[str]]:type word: str:rtype: bool"""if not word:return Trueif not board:return Falsefor i in range(len(board)):for j in range(len(board[0])):if self.dfs(board, word, i, j):return Truereturn Falsedef dfs(self, board, word, i, j):if board[i][j] == word[0]:if not word[1:]:return Trueboard[i][j] = " "if i > 0 and self.dfs(board, word[1:], i-1, j):return Trueif i < len(board)-1 and self.dfs(board, word[1:], i+1, j):return Trueif j > 0 and self.dfs(board, word[1:], i, j-1):return Trueif j < len(board[0])-1 and self.dfs(board, word[1:], i, j+1):return Trueboard[i][j] = word[0]return Falseelse:return False

LeetCode刷题(50)--Word Search相关推荐

  1. LeetCode刷题记录11——290. Word Pattern(easy)

    LeetCode刷题记录11--290. Word Pattern(easy) 目录 LeetCode刷题记录11--290. Word Pattern(easy) 题目 语言 思路 源码 后记 题目 ...

  2. LeetCode刷题记录9——58. Length of Last Word(easy)

    LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...

  3. ​LeetCode刷题实战50:Pow(x, n)

    算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试.所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 ! 今天和大家 ...

  4. Leetcode刷题指南和top100题目

    原文链接:https://blog.csdn.net/qq_39521554/article/details/79160815 参考博文:https://blog.csdn.net/mmc2015/a ...

  5. Leetcode刷题

    刷题 leetcode 1.两数之和 #哈希表 class Solution:def twoSum(self, nums: List[int], target: int) -> List[int ...

  6. Leetcode-How-What 力扣Leetcode刷题指南

    Leetcode-How-What 力扣Leetcode刷题指南 About the way how to use Leetcode wisely for preparing the intervie ...

  7. C#LeetCode刷题-树

    树篇 # 题名 刷题 通过率 难度 94 二叉树的中序遍历 61.6% 中等 95 不同的二叉搜索树 II 43.4% 中等 96 不同的二叉搜索树 51.6% 中等 98 验证二叉搜索树 22.2% ...

  8. C#LeetCode刷题-二分查找​​​​​​​

    二分查找篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30 ...

  9. C#LeetCode刷题-哈希表

    哈希表篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 42.8% 简单 3 无重复字符的最长子串   24.2% 中等 18 四数之和   ...

  10. C#LeetCode刷题-数组

    数组篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 43.1% 简单 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组 ...

最新文章

  1. 《机器学习Python实践》——数据导入(CSV)
  2. jquery iCheck 插件
  3. OpenCV视频中的人脸标志检测
  4. Mysql 5.8 参数调优
  5. 牛客 - 牛牛与牛妹的约会(贪心)
  6. 创建型模式——工厂模式
  7. 机器学习数据预处理代码汇总(最新更新20年3月1日)
  8. All Things Intelligence—Baidu World 2020
  9. C语言sopc蜂鸣器按键弹奏中音,五邑大学sopc实验报告:基于自定义PWM的乐曲演奏实验.doc...
  10. 详解如何提取Unity素材,源码
  11. Endnote 导出英文、中文(知网)参考文献进入Word
  12. python将电视剧按收视率进行排序_2019电视剧收视率排行榜
  13. 计算机所选区域单元格数值,筛选Excel2007单元格区域或表中的数据
  14. python制作京东评论词云图
  15. tomcat7w.exe启动失败,未注册成服务,以及配置Tomcat系统环境变量
  16. 有插件有技巧,Sketchup牛人必备!
  17. 快递物流行业:数据增量下载的实现
  18. 解决VScode创建Vue项目时一直显示downloading template的问题
  19. java html 双引号转义,java如何将单引号转义
  20. 如何实现模拟量信号远距离无线传输?

热门文章

  1. Virtual Box Host-Only网络模式配置
  2. MS SQL Server存储过程的优点有哪些呢?
  3. html5录音支持pc和Android、ios部分浏览器,微信也是支持的,JavaScript getUserMedia
  4. java中的类、成员变量、方法的修饰符。
  5. TCL_事务控制语言
  6. java推断字符串是否为乱码
  7. UVA12583_Memory Overow
  8. 基姆拉尔森星期计算公式
  9. qt project settings被禁用解决方案
  10. 死锁与活锁的原因 与解决方法(附加“饿死”)