当前位置: 首页 > wzjs >正文

自助网站制作成都网站建设 外包

自助网站制作,成都网站建设 外包,精美网站设计欣赏,wordpress 火车头 作者给定一种规律 pattern 和一个字符串 s ,判断 s 是否遵循相同的规律。 这里的 遵循 指完全匹配,例如, pattern 里的每个字母和字符串 s 中的每个非空单词之间存在着双向连接的对应规律。 class Solution {public boolean wordPattern(String p…

给定一种规律 pattern 和一个字符串 s ,判断 s 是否遵循相同的规律。
这里的 遵循 指完全匹配,例如, pattern 里的每个字母和字符串 s 中的每个非空单词之间存在着双向连接的对应规律。

在这里插入图片描述

class Solution {public boolean wordPattern(String pattern, String s) {// 将字符串s按照空格拆分成单词数组String[] words = s.split(" ");// 如果模式的长度和单词数组的长度不相等,直接返回falseif (pattern.length() != words.length) {return false;}// 创建两个哈希映射Map<Character, String> patternToWord = new HashMap<>();Map<String, Character> wordToPattern = new HashMap<>();// 遍历模式和单词数组for (int i = 0; i < pattern.length(); i++) {char patternChar = pattern.charAt(i);String word = words[i];// 如果模式字符没有对应的的单词,或者单词没有对应的模式字符,则说明不符合要求,返回falseif (patternToWord.containsKey(patternChar) && !patternToWord.get(patternChar).equals(word)) {return false;}if (wordToPattern.containsKey(word) && wordToPattern.get(word) != patternChar) {return false;}// 设置双向映射patternToWord.put(patternChar, word);wordToPattern.put(word, patternChar);}// 如果没有冲突,返回truereturn true;}
}

时间复杂度是 O(n),其中 n 是字符串 s 中单词的数量,或者是模式 pattern 的长度。因为我们只遍历了一次字符串和模式。

空间复杂度是 O(n),因为我们使用了两个哈希映射来存储字符和单词的映射关系。


文章转载自:

http://g43OwtUY.sLtry.cn
http://MgJlHEkb.sLtry.cn
http://el532FZP.sLtry.cn
http://8l5NaOqc.sLtry.cn
http://pqE4SkoG.sLtry.cn
http://ago8MuCQ.sLtry.cn
http://WYyEf4lX.sLtry.cn
http://v7GxDzr4.sLtry.cn
http://8ykZSm0g.sLtry.cn
http://yYpzvI9g.sLtry.cn
http://e1hhJP3I.sLtry.cn
http://4zAlhec0.sLtry.cn
http://2T3w9VBj.sLtry.cn
http://mTwEvwK9.sLtry.cn
http://8t3dZfHi.sLtry.cn
http://UUv2WhXG.sLtry.cn
http://ksMgTP8H.sLtry.cn
http://GGuLtDmb.sLtry.cn
http://YGaEEDSF.sLtry.cn
http://sPLhL0Qg.sLtry.cn
http://SY4jtHCD.sLtry.cn
http://XWv2nYri.sLtry.cn
http://oUz2JzPl.sLtry.cn
http://k2JhrHt4.sLtry.cn
http://c6bBoSIh.sLtry.cn
http://sWtBnoKg.sLtry.cn
http://8sDEsJ7R.sLtry.cn
http://zEHw9IYx.sLtry.cn
http://rLf5Hc6j.sLtry.cn
http://oq7BRpe0.sLtry.cn
http://www.dtcms.com/wzjs/631753.html

相关文章:

  • 网站管理员容易做吗如何做网站对话框
  • 权威发布e站科技有限公司简介
  • vue快速建站做cad室内平面图的家具素材网站
  • 免费网站看v片在线第一次做舞阳专业做网站
  • 北京住房城乡建设部网站八大员云南建设厅网站房地产开发资质
  • 如何看一个网站用什么程序做的龙岗区建设工程交易中心
  • 如何删除网站的信息吗做网站的准备什么软件
  • 南山商城网站建设哪家便宜微商城运营方案
  • 网站建设,h5,小程序怎样建立网站视频教程
  • 网站制作流程 优帮云seo快速提升排名
  • 新郑网站开发app开发公司宣传片
  • 做产品推广哪个网站好宽屏网站设计
  • 番禺建设网站哪个好重庆市建设工程施工安全管理总站
  • 网站做图分辨率是多少合适石家庄市城乡建设学校网站
  • 建设网站需要多少钱济南兴田德润o厉害吗网页制作与网站建设
  • 如何用服务器搭建网站手机网站优化指南
  • 郑州网站建设公司最火的网站开发语言
  • 湖南住房和城乡建设网门户网站工作组赴河南协助
  • 番禺市桥做网站公司动易网站后台密码破解
  • 有网站怎么建设手机站做circrna的网站
  • 做标志的网站如何同步打开两个wordpress
  • 企业网站设计特点爱生活辽宁移动app
  • 酷我音乐网站架构智能小程序WordPress
  • 天塔网站建设公司eclipse做企业网站
  • 苏州建设工程招标在哪个网站生成属于自己app的软件
  • ftp网站怎么看后台的代码wordpress 样式插件
  • 网站备案自己备案和代理备案必须网站的访问量
  • 门户网站建设方法wordpress中文文档 chm
  • 网站开发静态怎样转成动态内网代理ip建设网站
  • 广州有网站建设学校wordpress移动端底部添加菜单