题目描述:
Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.
A query word queries[i] matches pattern if you can insert lowercase English letters pattern so that it equals the query. You may insert each character at any position and you may not insert any characters.
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/camelcase-matching
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
代码:
class Solution {
public:
vector<bool> camelMatch(vector<string>& queries, string pattern) {
int len = queries.size();
vector<bool> ans(len,false);
for(int i = 0 ; i < queries.size() ; i++)
{
int l = 0 , r = 0;
bool temp = false;
while(l<queries[i].size())
{
if(r < pattern.size() && pattern[r] == queries[i][l])
{
r++;
}
else if(queries[i][l]>='A'&&queries[i][l]<='Z') // 有多余的大写
{
temp = true;
break;
}
l++;
}
if(!temp && r==pattern.size())
ans[i] = true;
}
return ans;
}
};