-
Notifications
You must be signed in to change notification settings - Fork 0
/
290_100
30 lines (30 loc) · 832 Bytes
/
290_100
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
bool wordPattern(string pattern, string str) {
string s[26] = {""};
int j = 0;
string k;
for(auto i:pattern){
k = "";
if(j == str.size())
return false;
while(str[j] != ' ' && j <= str.size() - 1){
k += str[j++];
if (j == str.size())
break;
}
j++;
if(s[i-'a'] == "")
s[i-'a'] = k;
else if (s[i-'a'] != k)
return false;
}
if(j != str.size() + 1)
return false;
for(int i = 0; i < 25; i ++)
for(int j = i + 1; j < 26; j ++)
if(s[i] == s[j] && s[i] != "")
return false;
return true;
}
};