LeetCode刷题(50)--Word Search
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相关推荐
- LeetCode刷题记录11——290. Word Pattern(easy)
LeetCode刷题记录11--290. Word Pattern(easy) 目录 LeetCode刷题记录11--290. Word Pattern(easy) 题目 语言 思路 源码 后记 题目 ...
- LeetCode刷题记录9——58. Length of Last Word(easy)
LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...
- LeetCode刷题实战50:Pow(x, n)
算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试.所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 ! 今天和大家 ...
- Leetcode刷题指南和top100题目
原文链接:https://blog.csdn.net/qq_39521554/article/details/79160815 参考博文:https://blog.csdn.net/mmc2015/a ...
- Leetcode刷题
刷题 leetcode 1.两数之和 #哈希表 class Solution:def twoSum(self, nums: List[int], target: int) -> List[int ...
- Leetcode-How-What 力扣Leetcode刷题指南
Leetcode-How-What 力扣Leetcode刷题指南 About the way how to use Leetcode wisely for preparing the intervie ...
- C#LeetCode刷题-树
树篇 # 题名 刷题 通过率 难度 94 二叉树的中序遍历 61.6% 中等 95 不同的二叉搜索树 II 43.4% 中等 96 不同的二叉搜索树 51.6% 中等 98 验证二叉搜索树 22.2% ...
- C#LeetCode刷题-二分查找
二分查找篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30 ...
- C#LeetCode刷题-哈希表
哈希表篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 42.8% 简单 3 无重复字符的最长子串 24.2% 中等 18 四数之和 ...
- C#LeetCode刷题-数组
数组篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 43.1% 简单 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组 ...
最新文章
- 《机器学习Python实践》——数据导入(CSV)
- jquery iCheck 插件
- OpenCV视频中的人脸标志检测
- Mysql 5.8 参数调优
- 牛客 - 牛牛与牛妹的约会(贪心)
- 创建型模式——工厂模式
- 机器学习数据预处理代码汇总(最新更新20年3月1日)
- All Things Intelligence—Baidu World 2020
- C语言sopc蜂鸣器按键弹奏中音,五邑大学sopc实验报告:基于自定义PWM的乐曲演奏实验.doc...
- 详解如何提取Unity素材,源码
- Endnote 导出英文、中文(知网)参考文献进入Word
- python将电视剧按收视率进行排序_2019电视剧收视率排行榜
- 计算机所选区域单元格数值,筛选Excel2007单元格区域或表中的数据
- python制作京东评论词云图
- tomcat7w.exe启动失败,未注册成服务,以及配置Tomcat系统环境变量
- 有插件有技巧,Sketchup牛人必备!
- 快递物流行业:数据增量下载的实现
- 解决VScode创建Vue项目时一直显示downloading template的问题
- java html 双引号转义,java如何将单引号转义
- 如何实现模拟量信号远距离无线传输?