我要在这里装个逼啦

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

leetcode Add and Search Word - Data structure design相关推荐

  1. LeetCode Add and Search Word - Data structure design(字典树)

    问题:设计一个支持addWord,search查询的数据结构,要求search支持.正则查询 思路:使用Trie数据结构,在匹配.时,从子结点中选取可行的一个继续匹配下一个字符,主要思路是基于递归 具 ...

  2. leetcode 211. Add and Search Word - Data structure design Trie树

    题目链接 写一个数据结构, 支持两种操作. 加入一个字符串, 查找一个字符串是否存在.查找的时候, '.'可以代表任意一个字符. 显然是Trie树, 添加就是正常的添加, 查找的时候只要dfs查找就可 ...

  3. leetcode 211. Design Add and Search Words Data Structure | 211. 添加与搜索单词 - 数据结构设计(Java)

    题目 https://leetcode.com/problems/design-add-and-search-words-data-structure/ 题解 字典树 + 深度优先搜素,思路参考 le ...

  4. 170. Two Sum III - Data structure design【easy】

    170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...

  5. LeetCode Two Sum III - Data structure design

    原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...

  6. TRIE - Data Structure

    Introduction 介绍 Trie,又称单词查找树,是一种树形结构,用于保存大量的字符串.它的优点是:利用字符串的公共前缀来节约存储空间. Trie is an ordered tree dat ...

  7. LeetCode 295. Find Median from Data Stream

    原题链接在这里:https://leetcode.com/problems/find-median-from-data-stream/ 题目: Median is the middle value i ...

  8. Data Structure

    Data Structure 1. Abstract Data Type (ADT) 1.1. Data type A set of objects + a set of operations Exa ...

  9. R语言ggplot2可视化:在选定数据点周围添加三角形(Add Triangles Around Select Data Points)

    R语言ggplot2可视化:在选定数据点周围添加三角形(Add Triangles Around Select Data Points) 目录

最新文章

  1. 审计风险控制流程的起点_审计理论结构的起点和逻辑起点辨析
  2. geotools的dotnet版本
  3. loadscript加载
  4. 进程间通信(5) 命名管道
  5. 【深入Java虚拟机JVM 09】JVM垃圾回收finalize方法--对象最有一次自我拯救
  6. java8 时间 LocalDateTime常用方法
  7. 转:谷歌离线地图基础
  8. Spring 入门学习二之IOC
  9. js解析json数组+java对象转json字符串
  10. 谷歌浏览器地址栏记录怎么删除 Chrome浏览器地址栏记录清除方法
  11. 如何打开mysql的批处理宫娥能_如何在MySQL中进行批处理插入
  12. php中取整的函数,利用PHP怎么对函数进行取整
  13. (84)FPGA显示激励(display)
  14. Dubbo学习笔记002---安装Zookeeper_并且安装Dubbo的管理控制台
  15. 1.4.PHP7.1 狐教程-环境(Mac下 PHP开发环境 配置及安装 php7.1.x nginx mysql)
  16. Matlab fftshift 详解
  17. 黑苹果 10.14.6 安装记录
  18. 学习游戏服务器编程进阶篇之全球同服技术架构
  19. centos7安装mysql5.5教程_Centos7.x下安装Mysql5.5、5.6、5.7三个版本全教程
  20. 计算机英语原文件夹,常用文件夹英文解译

热门文章

  1. mach-o格式分析
  2. 【问链财经-区块链基础知识系列】 第三十八课 以太坊智能合约账户全解析
  3. Gradle不匹配报错的终极大招(gradle插件版本和gradle版本对应关系)
  4. php怎么做签到系统,PHP如何实现签到功能
  5. 简述css布局技术的特点,div+css布局技术漫谈
  6. 微服务架构设计模式 pdf_六种常用的微服务架构设计模式之一: 入门级模式...
  7. 2022.2.28集成电子开关电路TWH8778
  8. Codeforces 1276C/1277F/1259F Beautiful Rectangle (构造)
  9. mysql8.0最低需要多少内存_MySQL8.0内存相关参数介绍
  10. pythonmax对字符_(MAX第五篇)Python--字符串操作(三)