作者归档:在线疯狂

RSS feed of 在线疯狂

[LeetCode]Word Search II

题目描述:

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 ...

继续阅读

[LeetCode]Add and Search Word - Data structure design

题目描述:

Design a data structure that supports the following two operations:

void addWord(word)
bool search(word)

search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any ...

继续阅读

[LeetCode]Implement Trie (Prefix Tree)

题目描述:

Implement a trie with insert, search, and startsWith methods.

Note:
You may assume that all inputs are consist of lowercase letters a-z.

题目大意:

实现字典树,包含插入,查找和前缀查找方法。

注意:

你可以假设所有的输入只包含小写字母a-z

解题思路:

本题考查字典树数据结构的基础知识。

Trie使用孩子表示法存储,TrieNode为字典树的节点,包含属性childs和isWord。

其中childs为dict,存储当前节点的后代节点;isWord为布尔值,表示当前节点是否存储了一个单词。

Python代码:

class ...

继续阅读