forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamelcase Matching.cpp
42 lines (37 loc) · 1.22 KB
/
Camelcase Matching.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
34
35
36
37
38
39
40
41
42
class Solution {
public:
vector<bool> camelMatch(vector<string>& queries, string pattern) {
vector<bool> res(queries.size());
for (int i = 0; i < queries.size(); i++)
{
int patRef = 0;
bool isCamel = true;
for (const char& ltr : queries[i])
{
if (patRef == pattern.size())
{
if (isupper(ltr))
{
isCamel = false;
break;
}
}
else
{
if (isupper(ltr) and isupper(pattern[patRef]) and ltr != pattern[patRef])
{
isCamel = false;
break;
}
else if (islower(ltr) and islower(pattern[patRef]) and ltr == pattern[patRef])
patRef++;
else if (ltr == pattern[patRef])
patRef++;
}
}
if (patRef == pattern.size() and isCamel)
res[i] = true;
}
return res;
}
};