LeetCode 1023

题目描述:

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;
    }
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值