Leetcode 1023. Camelcase Matching

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Camelcase Matching

2. Solution

  • Version 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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/
如果有收获,可以请我喝杯咖啡!