子串判断
来源:互联网 发布:淘宝退货售后卡填什么 编辑:程序博客网 时间:2024/06/06 22:45
难题,先mark:
leetcode之word ladder
/*最短搜索路径,所以是广度优先搜索(BFS)。按照定义,存在一个字母差异的单词为邻居,因此采用逐位替换字母并查找字典的方法寻找邻居。对队列中的每个单词记录路径长度。queue<pair<string,int> > q; 从start进入队列记作1.长度为i的字母的邻居,如果没有访问过,则路径长度为i+1*/class Change {public: int countChanges(vector<string> dic, int n, string s, string t) { vector<string>::iterator ite = find(dic.begin(),dic.end(),s); int result = BFS(s,t,dic); if(ite != dic.end()){ --result; }//if return result; }private: int BFS(string start,string end,vector<string> &dict){ if(start == end){ return 0; }//if // 存放单词和单词所在层次 queue<pair<string,int> > q; q.push(make_pair(start,1)); // 判断是否访问过 vector<string> visited; visited.push_back(start); while(!q.empty()){ pair<string,int> cur = q.front(); q.pop(); string word = cur.first; int size = word.size(); // 穷尽所有可能的变换 for(int i = 0;i < size;++i){ string newWord(word); // 每次只变换一个字符 有26种可能 for(int j = 0;j < 26;++j){ newWord[i] = 'a'+j; // 找到目标返回 if(newWord == end){ return cur.second + 1; }//if // 判断之前访问过或者是否在字典里 vector<string>::iterator ite = find(dict.begin(),dict.end(),newWord); vector<string>::iterator ite2 = find(visited.begin(),visited.end(),newWord); if(ite2 == visited.end() && ite != dict.end()){ visited.push_back(newWord); q.push(make_pair(newWord,cur.second+1)); }//if }//for }//for }//while return -1; }};
0 0
- 字符串判断子串
- 判断子串
- 子串判断
- 判断子串
- 例题:判断子串
- 判断子串的存在
- 判断是否含有子串
- 1.8 判断是否为旋转子串
- 字符串的最大回文子串判断
- 字符串判断子串存在性
- Palindrome后缀数组判断回文子串
- 【算法】最长回文子串的判断
- isSubstring子串判断笔试题
- strchr strstr (判断 子字符(串))
- 使用库函数判断是否子串
- C语言:字符串子串判断
- 判断是否为其子串
- 判断字符串是否包含子串 python
- ANDROID中自定义属性格式详解
- 华为服务器故障后的标准动作
- hdu5532 Almost Sorted Array(LIS)
- BZOJ1047: [HAOI2007]理想的正方形 单调队列
- 用maven打包dubbo项目并部署到云平台
- 子串判断
- 工厂方法模式
- Eclipse一直Building Workspace
- java中的构造函数
- Error:Execution failed for task ':app:clean'. > Unable to delete directory:......
- tomcat热部署配置
- 事务
- AOP应用——事务管理
- div 移动