leetcode Add and Search Word - Data structure design
生活随笔
收集整理的這篇文章主要介紹了
leetcode Add and Search Word - Data structure design
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我要在這里裝個逼啦?
class WordDictionary(object):def __init__(self):"""initialize your data structure here."""self._dict = {}def addWord(self, word):"""Adds a word into the data structure.:type word: str:rtype: void"""if len(word) not in self._dict:self._dict[len(word)] = [word]else:self._dict[len(word)].append(word)def search(self, word):"""Returns if the word is in the data structure. A word couldcontain the dot character '.' to represent any one letter.:type word: str:rtype: bool"""if len(word) not in self._dict:return Falsefor tag in self._dict[len(word)]:if self.simalor(tag, word):return Truereturn Falsedef simalor(self, word, patternword):for i in range(len(patternword)):if patternword[i] not in ('.', word[i]):return Falsereturn True
轉載于:https://www.cnblogs.com/dsdr/p/6063116.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的leetcode Add and Search Word - Data structure design的全部內容,希望文章能夠幫你解決所遇到的問題。