Leetcode 1023. Camelcase Matching

暴力查找

class Solution:
    def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:
        q_size=len(queries)
        p_size=len(pattern)
        ans=[True for i in range(q_size)]
        for i,query in enumerate(queries):
            idx=[query.find(pattern[0])]
            if idx[-1]==-1:
                ans[i]=False
                continue
            for p in pattern[1:]:
                id = query[idx[-1]+1:].find(p)
                if id==-1:
                    idx.append(-1)
                    break
                else:
                    idx.append(idx[-1]+1+id)
            if idx[-1]==-1:
                ans[i]=False
                continue
            for j,v in enumerate(query):
                if not (j in idx):
                    if not v.islower():
                        ans[i]=False
                        break
        return ans

 

posted @ 2019-04-24 17:52  周洋  阅读(374)  评论(0编辑  收藏  举报