如果我们可以将小写字母插入模式串 pattern 得到待查询项 query,那么待查询项与给定模式串匹配。(我们可以在任何位置插入每个字符,也可以插入 0 个字符。)
给定待查询列表 queries,和模式串 pattern,返回由布尔值组成的答案列表 answer。只有在待查项  queries[i] 与模式串 pattern 匹配时, answer[i]  才为 true,否则为 false。
题目链接:https://leetcode.cn/problems/camelcase-matching/
# 解题思路
双指针:详细看代码注释
# 执行结果

# 代码
class Solution {  | |
public List<Boolean> camelMatch(String[] queries, String pattern) {  | |
List<Boolean> ret = new ArrayList<>(queries.length);  | |
for (String s : queries) {  | |
ret.add(match(s, pattern));  | |
        } | |
return ret;  | |
    } | |
private boolean match(String s, String p) {  | |
if (s == null || p == null || p.length() < 1 || s.length() < p.length())  | |
return false;  | |
int ls = s.length(), ps = p.length();  | |
int j = 0;  | |
for (int i = 0; i < ls; ++i) {  | |
if (j < ps) {  | |
                // 相等,则往后匹配下一个字符 | |
if (p.charAt(j) == s.charAt(i)) ++j;  | |
else if (Character.isUpperCase(s.charAt(i))) {  | |
                    // 当前待匹配的字符为大写,且与 p 中当前待匹配的字符不相等 | |
return false;  | |
                } | |
                // 当前待匹配的字符为小写,可以通过添加获得,继续下一个 | |
} else if (Character.isUpperCase(s.charAt(i))) {  | |
                // 当前待匹配的字符为大写 | |
return false;  | |
            } | |
        } | |
        // 所有字符都匹配完成 | |
return j == ps;  | |
    } | |
} |