其他分享
首页 > 其他分享> > 1023. Camelcase Matching

1023. Camelcase Matching

作者:互联网

挺好写的。

class Solution {
public:
    
    bool judge(string query, string pattern){
        if (query.size() < pattern.size()){
            return false;
        }
    
        int ii = 0;
        int jj = 0;
        while(ii<query.size()&&jj<pattern.size()){
            if (query[ii]==pattern[jj]){
                ii ++;
                jj ++;
            }
            else{
                if (query[ii]>='A'&&query[ii]<='Z'){
                    return false;
                }
                else{
                    ii ++;
                }
            }
        }
        
        if (ii==query.size()&&jj==pattern.size()){
            return true;
        }
        else if (ii<query.size()&&jj==pattern.size()){
            for (int kk = ii;kk<query.size();kk++){
                if (query[kk]>='A'&&query[kk]<='Z'){
                    return false;
                }
            }
            return true;
        }
        else if (ii==query.size()&&jj<pattern.size()){
            return false;
        }
        else{
            cout<<"error"<<endl;
            return false;
        }
    }
    
    vector<bool> camelMatch(vector<string>& queries, string pattern) {
        vector<bool> res;
        for (int i=0;i<queries.size();i++){
            res.push_back(judge(queries[i], pattern));
        }
        return res;
    }
};
zeroQiaoba 发布了339 篇原创文章 · 获赞 18 · 访问量 14万+ 私信 关注

标签:string,1023,Camelcase,int,pattern,ii,query,Matching,size
来源: https://blog.csdn.net/zeroQiaoba/article/details/104518553