LeetCode刷题记录11——290. Word Pattern(easy)

目录

LeetCode刷题记录11——290. Word Pattern(easy)

题目

语言

思路

源码

后记


题目

本题输入是两个字符串,输出是true或者false。计算过程为:依照字符串pattern的模板,去看字符串str的格式是否与pattern的相匹配,是则true,否则false。举个例子:有点类似小时候成语的格式一样:红红火火(aabb)、不了了之(abba)……。这题类似:abba->dog cat cat dog。

语言

java

思路

并行查看模式和字符串,比较他们最后出现的索引。使用map创建一个对象mymap,使用mymap.put的方法,该方法的意思应该是:如果第二次put进同样的key不同value,返回的值是被挤掉的那个value!不然就是null。

源码

public boolean wordPattern(String pattern, String str) {String[] words = str.split(" ");if (words.length != pattern.length())return false;Map mymap = new HashMap();for (Integer i=0; i<words.length; ++i)if (mymap.put(pattern.charAt(i), i) != mymap.put(words[i], i))return false;return true;
}

后记

此题方法借鉴于Stefan Pochmann大神的思路,具体可看Stefan Pochmann大神的原话

LeetCode刷题记录11——290. Word Pattern(easy)相关推荐

  1. LeetCode刷题记录9——58. Length of Last Word(easy)

    LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...

  2. LeetCode刷题记录4——67. Add Binary(easy)

    LeetCode刷题记录4--67. Add Binary(easy) 目录 LeetCode刷题记录4--67. Add Binary(easy) 题目 语言 思路 后记 题目 今天这题是与字符串相 ...

  3. LeetCode刷题记录1——717. 1-bit and 2-bit Characters(easy)

    LeetCode刷题记录1--717. 1-bit and 2-bit Characters(easy) LeetCode刷题记录1--717. 1-bit and 2-bit Characters( ...

  4. 算法记录 牛客网 leetcode刷题记录

    算法记录 & 牛客网 & leetcode刷题记录 解题思路 STL容器 常用算法模板 堆排序 插入排序 快速排序 BFS层序遍历 二叉树 JZ55 二叉树的深度 BST(binary ...

  5. LeetCode刷题记录15——21. Merge Two Sorted Lists(easy)

    LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) 目录 LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) ...

  6. LeetCode刷题记录14——257. Binary Tree Paths(easy)

    LeetCode刷题记录14--257. Binary Tree Paths(easy) 目录 前言 题目 语言 思路 源码 后记 前言 数据结构感觉理论简单,实践起来很困难. 题目 给定一个二叉树, ...

  7. LeetCode刷题记录13——705. Design HashSet(easy)

    LeetCode刷题记录13--705. Design HashSet(easy) 目录 LeetCode刷题记录13--705. Design HashSet(easy) 前言 题目 语言 思路 源 ...

  8. LeetCode刷题记录12——232. Implement Queue using Stacks(easy)

    LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...

  9. LeetCode刷题记录10——434. Number of Segments in a String(easy)

    LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...

最新文章

  1. INFO org.apache.hadoop.ipc.RPC: Server at master/192.168.200.128:9000 not available yet, Zzzzz...
  2. python爬虫脚本ie=utf-8_Python反爬虫伪装浏览器进行爬虫
  3. 人脸识别测试维度定义(欢迎大家拍砖并补充谢谢!)
  4. Asp.net网站开发架构设计要求
  5. ip xfrm命令是做什么的?
  6. 点击按钮传递参数并调用ajax,jQuery 单击使用 jQuery 的按钮并在 ajax 成功后将数据附加到响应...
  7. copy php是否开启_命令行方式启动php服务
  8. Anaconda的安装与使用(Windows下)
  9. Linux 命令收集
  10. 少儿计算机基础知识,儿童计算机基本操作
  11. 论文课程设计--CRM客户管理系统
  12. 嵌入式软件分层设计思想
  13. NYOJ - [第十一届河南省程序设计大赛]治安管理(区间判断)
  14. cad2016的自动修复此计算机,CAD中遇到文件损坏,别着急,这几招能帮你挽回损失...
  15. IDEA 2020.1.2 无法显示图片的魔幻解决方法
  16. linux软路由 iptv,软路由实现任意端口看IPTV电视的方法
  17. 网络推广文案八大步,让你的朋友圈引人注目!
  18. mac pdf去水印_PDF水印工具for Mac-PDF水印工具Mac版下载 V1.7-PC6苹果网
  19. UVA 10635 Prince and Princess
  20. 通信协议分类(串行通信,并行通信,同步/异步,单工/双工,半双工/全双工)

热门文章

  1. java 中常用的类
  2. 中国互联网+光通信器件行业商业模式创新与投资机会深度研究报告
  3. Strusts2笔记7--国际化
  4. LTE QCI分类 QoS
  5. TimeQuest学习之三------外部寄存器模型
  6. virtual hust 2013.6.20 数论基础题目 D - Just the Facts
  7. flex java socket通信
  8. matlab getstart,matlab帮助文件(matlab get start.pdf)
  9. 方法 注释_注释模板导入操作方法
  10. xml放在工程的那个路径下_Ubuntu下配置pyrouge