Leetcode 1023. Camelcase Matching

2021-05-18 16:19:11 浏览数 (1)

1. Description

2. Solution

  • Version 1
代码语言:javascript复制
class Solution:
    def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:
        result = []
        for i in range(len(queries)):
            res = self.match(queries[i], pattern)
            result.append(res)
            
        return result


    def match(self, query, pattern):
        i = 0
        j = 0
        while i < len(query) and j < len(pattern):
            if query[i] == pattern[j]:
                i  = 1
                j  = 1
            else:
                if query[i].isupper():
                    return False
                else:
                    i  = 1

        if j == len(pattern) and (i == len(query) or query[i:].islower()):
            return True
        return False

Reference

  1. https://leetcode.com/problems/camelcase-matching/

0 人点赞