Word Search II 解题报告
来源:互联网 发布:淘宝买东西寄到国外 编辑:程序博客网 时间:2024/05/17 01:35
转载自:http://blog.csdn.net/ljiabin/article/details/45846527
【题目】
Given a 2D board and a list of words from the dictionary, find all words in the board.
Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
For example,
Given words = ["oath","pea","eat","rain"]
and board =
[ ['o','a','a','n'], ['e','t','a','e'], ['i','h','k','r'], ['i','f','l','v']]Return
["eat","oath"]
.Note:
You may assume that all inputs are consist of lowercase letters a-z
.
参考 【LeetCode】Word Search 解题报告 ,题目变成给定一组word,检查哪个word可以由board形成。
如果还按照DFS回溯的方法,逐个检查每个word是否在board里,显然效率是比较低的。我们可以利用Trie数据结构,也就是前缀树。然后dfs时,如果当前形成的单词不在Trie里,就没必要继续dfs下去了。如果当前字符串在trie里,就说明board可以形成这个word。
【Java代码】
Trie数据结构的实现在LeetCode上也有对应的题目 Implement Trie (Prefix Tree)
【Trie实现】
- Word Search II解题报告
- Word Search II 解题报告
- 【LeetCode】Word Search II 解题报告
- LeetCode-Word Search II-解题报告
- [leetcode] 212. Word Search II 解题报告
- [Leetcode] 212. Word Search II 解题报告
- Leetcode Word Search 解题报告
- 【LeetCode】Word Search 解题报告
- 【LeetCode】Word Search 解题报告
- [LeetCode] Word Search 解题报告
- [leetcode] 79. Word Search 解题报告
- [Leetcode] 79. Word Search 解题报告
- LeetCode — Word Break II 解题报告
- Leetcode Word Ladder II 解题报告
- LeetCode Word Break II 解题报告
- [LeetCode OJ] Word Break II 解题报告
- 【LeetCode】Word Break II 解题报告
- [leetcode] 140. Word Break II 解题报告
- 微信支付快速集成
- DB2删除完数据之后,如何释放LOB字段占用的空间
- android 7.0 相机拍照和裁剪适配
- 客户端websocket(C#)长连接及简易RPC框架设计(一)
- 继承和多态
- Word Search II 解题报告
- [DP]城市交通
- 【支付宝】支付宝支付失败:4000
- Linux Min
- VS编译环境中TBB配置和C++中lambda表达式
- Redis常见七种使用
- java : Maven in action (Maven 3 实战) 中文目录
- 关于C语言的malloc函数以及内存泄漏的问题
- HTML5基础——文本标记