Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- **/
- class Solution {
- public:
- bool wordPattern(string pattern, string str) {
- unordered_map<string, int>w2i;
- unordered_map<char, int>c2i;
- int n = (int)pattern.size();
- int i=0;
- istringstream in(str);
- for(string word; in >> word; i++ )
- {
- if( i == n || w2i[word] != c2i[pattern[i]] )
- return false;
- w2i[word] = c2i[pattern[i]] = i+1;
- }
- return i == n;
- }
- };
Add Comment
Please, Sign In to add comment