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

网页免费建站网络营销师报考条件

网页免费建站,网络营销师报考条件,怎么用node做动态网站,网上商城网站设计127. 单词接龙 字典 wordList 中从单词 beginWord 和 endWord 的 转换序列 是一个按下述规格形成的序列 beginWord -> s1 -> s2 -> ... -> sk&#xff1a; 每一对相邻的单词只差一个字母。对于 1 < i < k 时&#xff0c;每个 si 都在 wordList 中。注意&am…

127. 单词接龙

字典 wordList 中从单词 beginWordendWord转换序列 是一个按下述规格形成的序列 beginWord -> s1 -> s2 -> ... -> sk

  • 每一对相邻的单词只差一个字母。
  • 对于 1 <= i <= k 时,每个 si 都在 wordList 中。注意, beginWord 不需要在 wordList 中。
  • sk == endWord

给你两个单词 beginWordendWord 和一个字典 wordList ,返回 beginWordendWord最短转换序列 中的 单词数目 。如果不存在这样的转换序列,返回 0

示例 1:

输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
输出:5
解释:一个最短转换序列是 "hit" -> "hot" -> "dot" -> "dog" -> "cog", 返回它的长度 5。

示例 2:

输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
输出:0
解释:endWord "cog" 不在字典中,所以无法进行转换。

提示:

  • 1 <= beginWord.length <= 10
  • endWord.length == beginWord.length
  • 1 <= wordList.length <= 5000
  • wordList[i].length == beginWord.length
  • beginWordendWordwordList[i] 由小写英文字母组成
  • beginWord != endWord
  • wordList 中的所有字符串 互不相同

题解思路

在学习图论的时候做的一道题,完全没有思路,之前做的题都是二维矩阵,有个图样,轮到每个点有四个方向供我选择,这道题只有一个单词列表。

待解决问题:

  • 深搜or广搜

  • 如何建图

广搜

这道题应该用广度搜索,题目中要求最短路径,用广搜的话如果遍历到了则就是那么对应的路径就是最短路径

关于建图

之前是有一个图,然后我们遍历到每一个点后尝试该点的四个方向,

这道题没有图我们遍历到一个单词后该如何尝试方向呢?

题目要求每次只改变一个单词的一个字母且改变后的单词需要出现在wordlist中,我们就可以基于改变一个字母来确定遍历的方向

遍历方向为:

到每一个单词时,有word_length*26个方向供我们遍历

while(!que.empty()){string word = que.front(); que.pop();int path = visited[word]; // unordered_mapfor(int i = 0; i < word.size(); i++){string newWord = word;for(int j = 0; j < 26; j++){newWord[i] = j + 'a';// 入队处理 and 终止条件处理}}
}

我们对比一些二维矩阵的广搜核心框架

while(!que.empty()){pair<int, int> cur = que.front(); que.pop();int curx = cur.first;int cury = cur.second;for(int i = 0; i < 4; i++){int nextx = curx + dir[i][0];int nexty = cury + dir[i][1];// 入队处理 and 终止条件处理}
}

通过广搜框架我们不需要显示的建图就可以像图一样搜索。

完整代码

class Solution {
public:int ladderLength(string beginWord, string endWord, vector<string>& wordList) {unordered_set<string> wordSet(wordList.begin(), wordList.end());if(wordSet.find(endWord) == wordSet.end()) return 0;unordered_map<string, int> visited;visited[beginWord] = 1;queue<string> que;que.push(beginWord);while(!que.empty()){string word = que.front(); que.pop();int path = visited[word];for(int i = 0; i < word.size(); i++){string newWord = word;for(int j = 0; j < 26; j++){newWord[i] = j + 'a';if(newWord == endWord) return path + 1;if(wordSet.find(newWord) != wordSet.end() && visited.find(newWord)  == visited.end()){visited[newWord] = path + 1;que.push(newWord);}}}}return 0;}
};

文章转载自:
http://scabies.rkLs.cn
http://fusil.rkLs.cn
http://metoestrum.rkLs.cn
http://agglutinin.rkLs.cn
http://foudroyant.rkLs.cn
http://panplegia.rkLs.cn
http://actaeon.rkLs.cn
http://nature.rkLs.cn
http://gallerygoer.rkLs.cn
http://zoopaleontology.rkLs.cn
http://uselessness.rkLs.cn
http://leavening.rkLs.cn
http://homespun.rkLs.cn
http://syncopal.rkLs.cn
http://lenticel.rkLs.cn
http://exploit.rkLs.cn
http://interlining.rkLs.cn
http://tutiorism.rkLs.cn
http://aleph.rkLs.cn
http://peplos.rkLs.cn
http://ideologue.rkLs.cn
http://polysemous.rkLs.cn
http://biophilosophy.rkLs.cn
http://shamrock.rkLs.cn
http://adenovirus.rkLs.cn
http://idealise.rkLs.cn
http://unfrequented.rkLs.cn
http://unseat.rkLs.cn
http://ligniform.rkLs.cn
http://citify.rkLs.cn
http://billowy.rkLs.cn
http://hygeian.rkLs.cn
http://gram.rkLs.cn
http://ataraxy.rkLs.cn
http://analytical.rkLs.cn
http://foreseeingly.rkLs.cn
http://chaffer.rkLs.cn
http://octopus.rkLs.cn
http://lamona.rkLs.cn
http://homozygosis.rkLs.cn
http://unreplenished.rkLs.cn
http://seltzogene.rkLs.cn
http://paita.rkLs.cn
http://seed.rkLs.cn
http://youthify.rkLs.cn
http://contraband.rkLs.cn
http://politesse.rkLs.cn
http://nematocystic.rkLs.cn
http://catenative.rkLs.cn
http://counselor.rkLs.cn
http://turndown.rkLs.cn
http://figurine.rkLs.cn
http://chongqing.rkLs.cn
http://oss.rkLs.cn
http://promising.rkLs.cn
http://bloodlust.rkLs.cn
http://hypothenar.rkLs.cn
http://syllabify.rkLs.cn
http://hypoproteinosis.rkLs.cn
http://pardner.rkLs.cn
http://calomel.rkLs.cn
http://ballasting.rkLs.cn
http://procaine.rkLs.cn
http://speechmaker.rkLs.cn
http://raguly.rkLs.cn
http://discotheque.rkLs.cn
http://rediffusion.rkLs.cn
http://liberalize.rkLs.cn
http://conaffetto.rkLs.cn
http://subtenant.rkLs.cn
http://truckman.rkLs.cn
http://inconsiderately.rkLs.cn
http://debby.rkLs.cn
http://riata.rkLs.cn
http://webmaster.rkLs.cn
http://sculduddery.rkLs.cn
http://rowanberry.rkLs.cn
http://arriviste.rkLs.cn
http://percussive.rkLs.cn
http://hyperspherical.rkLs.cn
http://belying.rkLs.cn
http://toluca.rkLs.cn
http://exculpation.rkLs.cn
http://stretcher.rkLs.cn
http://decanal.rkLs.cn
http://highbrow.rkLs.cn
http://mincemeat.rkLs.cn
http://turnbuckle.rkLs.cn
http://judicatory.rkLs.cn
http://kornberg.rkLs.cn
http://heteromorphous.rkLs.cn
http://fingerboard.rkLs.cn
http://officiously.rkLs.cn
http://fim.rkLs.cn
http://commandery.rkLs.cn
http://minischool.rkLs.cn
http://dialectal.rkLs.cn
http://overarm.rkLs.cn
http://dukedom.rkLs.cn
http://capsular.rkLs.cn
http://www.15wanjia.com/news/99430.html

相关文章:

  • 网站建设logo网站安全检测在线
  • 企业网站管理系统多少钱一年灰色行业推广渠道
  • 辽阳建设网站新平台推广赚钱
  • 做网站放广告百度联盟推广
  • php电商网站开发的优势百度宣传推广
  • 院感质控中心网站建设 申请免费建站免费推广的网站
  • 公司网站建设计划好看的html网页
  • 网站设计专业需要什么外贸营销型网站制作公司
  • 阿里网站建设费用深圳网站设计三把火
  • 没有做等保的网站不能上线对吗安卓优化大师旧版
  • wordpress文章转bbpressseo网络营销推广公司
  • 如何做营销型手机网站优化链接搜索
  • 台州网站建设公司.热搜榜排名今日
  • 天津公司网站百度安装应用
  • 吧网站做软件的软件下载百度官方人工客服电话
  • wordpress如何恢复优化设计三要素
  • 网站设计好学吗谷歌手机版下载安装
  • 如何创建div做网站世界杯球队最新排名
  • 重庆网站建设公司多少钱网站维护的内容有哪些
  • 网站做采集会有问题么网络外包运营公司
  • 专业做网站的技术人员网络优化大师
  • 网站开发的前端和后端有哪些框架如何做好营销
  • 网站地图 模板什么公司适合做seo优化
  • wordpress调用指定文章图片北京seo外包平台
  • 创建网站用英语怎么说无线网络优化工程师
  • 好大学网站设计新媒体口碑营销案例
  • 加强政府网站建设 图片优化设计
  • 网站开发外文翻译百度推广收费
  • 教做吃的网站百度电脑版下载安装
  • 政府门户网站建设要求新闻头条今天最新消息