当前位置:
首页 >
leetcode Add and Search Word - Data structure design
发布时间:2025/3/14
47
豆豆
生活随笔
收集整理的这篇文章主要介绍了
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的全部内容,希望文章能够帮你解决所遇到的问题。