-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathareFollowingPatterns.cpp
33 lines (31 loc) · 1.08 KB
/
areFollowingPatterns.cpp
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
31
32
33
/* Coding challenge "areFollowingPatterns from CodeFights */
struct Info {
int count;
int index;
int lastIndex;
};
bool areFollowingPatterns(std::vector<std::string> strings, std::vector<std::string> patterns) {
std::map<std::string,std::string> matchingHashmapStrings;
std::map<std::string,std::string> matchingHashmapPatterns;
for (int i = 0; i < strings.size(); ++i) {
auto itMap = matchingHashmapStrings.find(strings[i]);
if (itMap != matchingHashmapStrings.end()) {
if (itMap->second != patterns[i])
return false;
}
else {
matchingHashmapStrings.insert(std::make_pair(strings[i],patterns[i]));
}
}
for (int i = 0; i < patterns.size(); ++i) {
auto itMap = matchingHashmapPatterns.find(patterns[i]);
if (itMap != matchingHashmapPatterns.end()) {
if (itMap->second != strings[i])
return false;
}
else {
matchingHashmapPatterns.insert(std::make_pair(patterns[i],strings[i]));
}
}
return true;
}