我要在这里装个逼啦

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 could
        contain the dot character '.' to represent any one letter.
        :type word: str
        :rtype: bool
        """
        if len(word) not in self._dict:
            return False

        for tag in self._dict[len(word)]:
            if self.simalor(tag, word):
                return True
        return False

    def simalor(self, word, patternword):

        for i in range(len(patternword)):
            if patternword[i] not in ('.', word[i]):
                return False
        return True

  

leetcode Add and Search Word - Data structure design的更多相关文章

  1. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  2. LeetCode——Add and Search Word - Data structure design

    Description: Design a data structure that supports the following two operations: void addWord(word) ...

  3. LeetCode Add and Search Word - Data structure design (trie树)

    题意:实现添加单词和查找单词的作用,即实现字典功能. 思路:'.' 可以代表一个任何小写字母,可能是".abc"或者"a.bc"或者"abc.&quo ...

  4. leetcode面试准备:Add and Search Word - Data structure design

    leetcode面试准备:Add and Search Word - Data structure design 1 题目 Design a data structure that supports ...

  5. 字典树(查找树) leetcode 208. Implement Trie (Prefix Tree) 、211. Add and Search Word - Data structure design

    字典树(查找树) 26个分支作用:检测字符串是否在这个字典里面插入.查找 字典树与哈希表的对比:时间复杂度:以字符来看:O(N).O(N) 以字符串来看:O(1).O(1)空间复杂度:字典树远远小于哈 ...

  6. 【LeetCode】211. Add and Search Word - Data structure design

    Add and Search Word - Data structure design Design a data structure that supports the following two ...

  7. 【刷题-LeetCode】211. Add and Search Word - Data structure design

    Add and Search Word - Data structure design Design a data structure that supports the following two ...

  8. LeetCode208 Implement Trie (Prefix Tree). LeetCode211 Add and Search Word - Data structure design

    字典树(Trie树相关) 208. Implement Trie (Prefix Tree) Implement a trie with insert, search, and startsWith  ...

  9. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

随机推荐

  1. root用户自动登录

    编辑文件: /etc/gdm/custom.conf的内容: 1 # GDM configuration storage      2       3 [daemon]      4 #GtkModu ...

  2. Java反射机制(Reflection)

    Java反射机制(Reflection) 一.反射机制是什么 Java反射机制是程序在运行过程中,对于任意一个类都能够知道这个类的所有属性和方法;对于任意一个对象都能够调用它的任意一个方法和属性,这种 ...

  3. PHP实现各种经典算法

    <?  //--------------------  // 基本数据结构算法 //--------------------  //二分查找(数组里查找某个元素)  function bin_s ...

  4. clang

    1.安装 clang 可以从官网下载,如果是CentOS 6 系统,也可以在 /etc/yum.repos.d/ 目录下增加一个 epel.repo 文件,内容如下: [epel] name=Extr ...

  5. css3动画由浅入深总结

    阅读目录 一:过渡动画---Transitions 二:Animations功能 三:translate(tx,ty) 四:scale(x,y) 五:rotate(x): 5.1:skew(x,y): ...

  6. mock.js-无需等待,让前端独立于后端进行开发

    概述 首先啦,我不认识mock.js的作者,带着需求找到mock.js让我觉得很惊艳. 相对于其他同类的框架的实现,mock.js超出了我的意料. 基于 数据模板 生成模拟数据. 基于 HTML模板 ...

  7. UML之用例图

    用例图概要 ²用例图是被称为参与者的外部用户所能观察到的系统功能的模型图. (<UML参考手册>) ²用例图列出系统中的用例和系统外的参与者,并显示哪个参与者参与了哪个用例的执行 (或称为 ...

  8. ICloud没有密码怎么注销?

    忘了密码的用这方法就可以啦1.现在我说你做 . 先进入 iCloud 点击 某某账户(要删的账户)2.第二栏密码那里删除原来的再输入ios(任意密码)3.然后点完成 之后会出现错误.请点 好.然后左上 ...

  9. PHP中PSR-[0-4]代码规范

    PHP-FIG 在说啥是PSR-[0-4]规范的之前,我觉得我们有必要说下它的发明者和规范者:PHP-FIG,它的网站是:www.php-fig.org.就是这个联盟组织发明和创造了PSR-[0-4] ...

  10. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...