-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem_1023_camelMatch.cc
59 lines (53 loc) · 1.13 KB
/
Problem_1023_camelMatch.cc
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <pthread.h>
#include <cctype>
#include <iostream>
#include <vector>
#include "UnitTest.h"
using namespace std;
class Solution
{
public:
vector<bool> camelMatch(vector<string> &queries, string pattern)
{
int n = queries.size();
int m = pattern.length();
vector<bool> ans(n, true);
for (int i = 0; i < n; i++)
{
int k = 0;
for (auto &c : queries[i])
{
if (k < m && pattern[k] == c)
{
k++;
}
else if (isupper(c))
{
ans[i] = false;
break;
}
}
if (k < m)
{
ans[i] = false;
}
}
return ans;
}
};
void testCamelMatch()
{
Solution s;
vector<string> q1 = {"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"};
vector<bool> o1 = {true, false, true, true, false};
vector<string> q2 = {"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"};
vector<bool> o2 = {false, true, false, false, false};
EXPECT_TRUE(o1 == s.camelMatch(q1, "FB"));
EXPECT_TRUE(o2 == s.camelMatch(q2, "FoBaT"));
EXPECT_SUMMARY;
}
int main()
{
testCamelMatch();
return 0;
}