leetcode 211. Add and Search Word - Data structure design
2017-08-15 14:03
477 查看
class WordDictionary(object): """ https://discuss.leetcode.com/topic/29809/python-168ms-beat-100-solution """ def __init__(self): """ Initialize your data structure here. """ self.words = collections.defaultdict(list) def addWord(self, word): """ Adds a word into the data structure. :type word: str :rtype: void """ self.words[len(word)].append(word) def search(self, word): """ Returns if the word is in the data structure. A word could contain the dot character '.' to represent any one letter. :type word: str :rtype: bool """ for a in self.words[len(word)]: for i,c in enumerate(word): if a[i] != c and c != '.': break else: return True return False # Your WordDictionary object will be instantiated and called as such: # obj = WordDictionary() # obj.addWord(word) # param_2 = obj.search(word)
相关文章推荐
- Leetcode 211 Add and Search Word - Data structure design
- Leetcode 211. Add and Search Word - Data structure design
- leetcode 211. Add and Search Word - Data structure design
- LeetCode-211.Add and Search Word - Data structure design
- 【LeetCode】211. Add and Search Word - Data structure design 解题报告(Python)
- Leetcode 211 Add and Search Word - Data structure design
- LeetCode 211. Add and Search Word - Data structure design
- LeetCode 211 Add and Search Word - Data structure design(字典树)
- LeetCode 211 - Add and Search Word - Data structure design
- Leetcode 211. Add and Search Word - Data structure design
- LeetCode 211 - Add and Search Word - Data structure design
- Leetcode211 - Add and Search Word - Data structure design
- LeetCode208 Implement Trie (Prefix Tree). LeetCode211 Add and Search Word - Data structure design
- LeetCode211:Add and Search Word - Data structure design
- Leetcode 211. Add and Search Word - Data structure design
- leetcode:Trie:Add and Search Word - Data structure design(211)
- [Leetcode]211. Add and Search Word - Data structure design @python
- [leetcode]211. Add and Search Word - Data structure design
- Leetcode 211. Add and Search Word - Data structure design
- [Leetcode] 211. Add and Search Word - Data structure design 解题报告