leetcode 290.Word Pattern
来源:互联网 发布:linux apr版本 编辑:程序博客网 时间:2024/05/16 12:18
class Solution {
public:
bool wordPattern(string pattern, string str) {
unordered_map<char, int>map;
unordered_map<string, int> map2;
istringstream in(str);
int i=0;
int n=(int)pattern.size();
for(string word;in>>word;i++)
{
if(map[pattern[i]]==0)
map[pattern[i]]=i+1;
if(map2[word]==0)
map2[word]=i+1;
if(i==n||map[pattern[i]]!=map2[word])
return false;
}
if(i<=n-1)
return false;
return true;
}
public:
bool wordPattern(string pattern, string str) {
unordered_map<char, int>map;
unordered_map<string, int> map2;
istringstream in(str);
int i=0;
int n=(int)pattern.size();
for(string word;in>>word;i++)
{
if(map[pattern[i]]==0)
map[pattern[i]]=i+1;
if(map2[word]==0)
map2[word]=i+1;
if(i==n||map[pattern[i]]!=map2[word])
return false;
}
if(i<=n-1)
return false;
return true;
}
};
耗时好久 不管了
阅读全文
0 0
- 【leetcode】290. Word Pattern
- 【leetcode】290. Word Pattern
- 290. Word Pattern LeetCode
- 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
- 290.[Leetcode]Word Pattern
- [Leetcode]290. Word Pattern
- LeetCode 290. Word Pattern
- 2985:数字组合(2.6基本算法之动态规划)
- Gym-101490H
- 找字符串中首次出现3次某个字符
- 删除子串
- 原创马踏联营
- leetcode 290.Word Pattern
- include<filename>和#include"filename"的区别
- .tar.bz2文件解压命令
- Composer安装Thinkphp5
- 将项目发布到Maven中央库
- Java之assert方法使用
- 最全Pycharm教程(40)——Pycharm扩展功能之捆绑插件TextMate
- EOJ 3329 dp
- C#中base64 bytes[] Stream之间的相互转换以及PDF转成图片