Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7892a19

Browse files
1023 Camelcase Matching.py
1 parente028189 commit7892a19

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

‎1023 Camelcase Matching.py‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/python3
2+
"""
3+
A query word matches a given pattern if we can insert lowercase letters to the
4+
pattern word so that it equals the query. (We may insert each character at any
5+
position, and may insert 0 characters.)
6+
7+
Given a list of queries, and a pattern, return an answer list of booleans, where
8+
answer[i] is true if and only if queries[i] matches the pattern.
9+
10+
Example 1:
11+
12+
Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer",
13+
"ForceFeedBack"], pattern = "FB"
14+
Output: [true,false,true,true,false]
15+
Explanation:
16+
"FooBar" can be generated like this "F" + "oo" + "B" + "ar".
17+
"FootBall" can be generated like this "F" + "oot" + "B" + "all".
18+
"FrameBuffer" can be generated like this "F" + "rame" + "B" + "uffer".
19+
Example 2:
20+
21+
Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer",
22+
"ForceFeedBack"], pattern = "FoBa"
23+
Output: [true,false,true,false,false]
24+
Explanation:
25+
"FooBar" can be generated like this "Fo" + "o" + "Ba" + "r".
26+
"FootBall" can be generated like this "Fo" + "ot" + "Ba" + "ll".
27+
Example 3:
28+
29+
Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer",
30+
"ForceFeedBack"], pattern = "FoBaT"
31+
Output: [false,true,false,false,false]
32+
Explanation:
33+
"FooBarTest" can be generated like this "Fo" + "o" + "Ba" + "r" + "T" + "est".
34+
35+
Note:
36+
1 <= queries.length <= 100
37+
1 <= queries[i].length <= 100
38+
1 <= pattern.length <= 100
39+
All strings consists only of lower and upper case English letters.
40+
"""
41+
fromtypingimportList
42+
43+
44+
classSolution:
45+
defcamelMatch(self,queries:List[str],pattern:str)->List[bool]:
46+
ret= []
47+
forqinqueries:
48+
ret.append(self.match(q,pattern))
49+
50+
returnret
51+
52+
defmatch(self,q,p):
53+
i=0
54+
j=0
55+
whilei<len(q)andj<len(p):
56+
ifq[i]==p[j]:
57+
i+=1
58+
j+=1
59+
elifq[i].islower():
60+
i+=1
61+
else:
62+
break
63+
64+
whilei<len(q)andq[i].islower():
65+
i+=1
66+
67+
returni==len(q)andj==len(p)
68+
69+
70+
if__name__=="__main__":
71+
assertSolution().camelMatch(["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"],"FoBa")== [True,False,True,False,False]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp