Leetcode 290 Word Pattern
来源:互联网 发布:鉴别声音的软件 编辑:程序博客网 时间:2024/06/14 01:13
Leetcode 290 Word Pattern
class Solution {public: bool wordPattern(string pattern, string str) { unordered_map<char,string> wordPattern1; unordered_map<string,char> wordPattern2; vector<string> wordString; int pos = 0; for(int i = 0;i < str.length();i ++) { if(str[i] == ' ') { string tmp = str.substr(pos,i-pos); pos = i + 1; wordString.push_back(tmp); } if(i == str.length() - 1) { wordString.push_back(str.substr(pos,i-pos+1)); } } if(pattern.length() != wordString.size()) return false; for(int i = 0;i < pattern.length();i ++) { if(wordPattern1.find(pattern[i]) == wordPattern1.end() && wordPattern2.find(wordString[i]) == wordPattern2.end()) { wordPattern1[pattern[i]] = wordString[i]; wordPattern2[wordString[i]] = pattern[i]; } else if(wordPattern1[pattern[i]] != wordString[i] || wordPattern2[wordString[i]] != pattern[i]) return false; } return true; }};
阅读全文
0 0
- leetcode 290: Word Pattern
- [leetcode 290]Word Pattern
- LeetCode 290 Word Pattern
- [LeetCode 290] Word Pattern
- leetcode 290 Word Pattern
- [leetcode 290] Word Pattern
- LeetCode 290 Word Pattern
- 【LEETCODE】290-Word Pattern
- LeetCode 290:Word Pattern
- leetcode 290 Word Pattern
- leetcode 290: Word Pattern
- 【LeetCode-290】Word Pattern
- LeetCode 290 Word Pattern
- leetcode 290:Word Pattern
- LeetCode[290] Word Pattern
- Leetcode 290 Word Pattern
- [leetcode][290]Word Pattern
- leetcode-290-Word Pattern
- Service源码分析系列(二):bindService流程分析
- Leetcode 172 Factorial Trailing Zeroes
- linux 安装mysql
- PointT
- 深度探索C++ 对象模型【第一章1】
- Leetcode 290 Word Pattern
- 区块链有哪些技术特征
- OSGi规范与原理(杂)
- Spark-core 运行原理
- MySql数据表查询
- Leetcode 38 Count and Say
- 多彩贵州风,爽爽的贵阳-记录我的国庆贵州行
- 【libevent】源码分析(3)-Libevent工作流程探究
- C语言写选择排序法