-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamelcaseMatching.cpp
More file actions
31 lines (29 loc) · 909 Bytes
/
camelcaseMatching.cpp
File metadata and controls
31 lines (29 loc) · 909 Bytes
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
// Source: https://leetcode.com/problems/camelcase-matching/
// Author: Miao Zhang
// Date: 2021-04-03
class Solution {
public:
vector<bool> camelMatch(vector<string>& queries, string pattern) {
vector<bool> res;
for (const string& q: queries) {
res.push_back(match(q, pattern));
}
return res;
}
private:
bool match(const string& q, const string& p) {
cout << q << "," << p;
int qn = q.length();
int pn = p.length();
int i = 0;
int j = 0;
for (i = 0; i < qn; i++) {
if (j == pn && isupper(q[i])) return false;
if ((j == pn || isupper(p[j])) && islower(q[i])) continue;
if ((isupper(p[j]) || isupper(q[i])) && p[j] != q[i]) return false;
if (islower(p[j]) && p[j] != q[i]) continue;
j++;
}
return i == qn && j == pn;
}
};