[leetcode] Word Pattern
来源:互联网 发布:vm linux 共享文件夹 编辑:程序博客网 时间:2024/06/07 07:12
注意一一对应即可:
class Solution {public: bool wordPattern(string pattern, string str) { int i = -1, pos = 0; unordered_map<string, char> mp; unordered_set<char> st; while(++i < pattern.length() && pos != string::npos) { string s; int nPos = str.find(' ', pos); if(nPos != string::npos) s = str.substr(pos, nPos - pos); else s = str.substr(pos); if(mp.find(s) == mp.end()) { if(st.find(pattern[i]) != st.end()) return false; mp[s] = pattern[i]; st.insert(pattern[i]); } if(i != 0 && mp[s] != pattern[i]) return false; if(nPos == string::npos) { pos = nPos; break; } pos = nPos + 1; } if(i != pattern.length() - 1 || pos != string::npos) return false; return true; }};
0 0
- leetcode | Word Pattern
- 【leetcode】290. Word Pattern
- leetcode 290: Word Pattern
- [Leetcode]Word Pattern
- [leetcode 290]Word Pattern
- LeetCode 290 Word Pattern
- 【leetcode】290. Word Pattern
- [LeetCode 290] Word Pattern
- leetcode 290 Word Pattern
- LeetCode 2 Word Pattern
- leetcode word-pattern
- leetcode: Word Pattern
- leetcode:Word Pattern
- [Leetcode]Word Pattern
- LeetCode Word Pattern
- LeetCode-Word Pattern
- LeetCode:Word Pattern
- leetcode之Word Pattern
- Apache 代理nodejs
- 蓝桥杯 查找整数
- 【FastDev4Android框架开发】AndroidAnnnotations注入框架使用之注入组件Components(九)
- android View 系统 touch 事件处理
- 1080. Graduate Admission (30)【排序】——PAT (Advanced Level) Practise
- [leetcode] Word Pattern
- zookeeper的领导者选举和原子广播
- CSS学习(十八)-滚动条、拖动元素、轮廓线
- Android 性能优化之使用MAT分析内存泄露问题
- web页面局部刷新问题
- android_广播者监听软件的安装和卸载
- 待思考的问题
- ||OC||OC语言基础知识框架结构//个人整理使用|仅供参考|尚未整理完
- 113. Path Sum II