|
1 | 1 | [#1023-camelcase-matching]
|
2 |
| -= 1023. Camelcase Matching |
| 2 | += 1023. 驼峰式匹配 |
3 | 3 |
|
4 |
| -{leetcode}/problems/camelcase-matching/[LeetCode - Camelcase Matching^] |
| 4 | +https://leetcode.cn/problems/camelcase-matching/[LeetCode - 1023. 驼峰式匹配 ^] |
5 | 5 |
|
6 |
| -A query word matches a given `pattern` if we can insert *lowercase* letters to the pattern word so that it equals the `query`. (We may insert each character at any position, and may insert 0 characters.) |
| 6 | +给你一个字符串数组 `queries`,和一个表示模式的字符串 `pattern`,请你返回一个布尔数组 `answer` 。只有在待查项 `queries[i]` 与模式串 `pattern` 匹配时, `answer[i]` 才为 `true`,否则为 `false`。 |
7 | 7 |
|
8 |
| -Given a list of `queries`, and a `pattern`, return an `answer` list of booleans, where `answer[i]` is true if and only if `queries[i]` matches the `pattern`. |
| 8 | +如果可以将**小写字母**插入模式串 `pattern` 得到待查询项 `queries[i]`,那么待查询项与给定模式串匹配。可以在任何位置插入每个字符,也可以不插入字符。 |
9 | 9 |
|
10 |
| - |
| 10 | +*示例 1:* |
11 | 11 |
|
12 |
| -*Example 1:* |
| 12 | +.... |
| 13 | +输入:queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB" |
| 14 | +输出:[true,false,true,true,false] |
| 15 | +示例: |
| 16 | +"FooBar" 可以这样生成:"F" + "oo" + "B" + "ar"。 |
| 17 | +"FootBall" 可以这样生成:"F" + "oot" + "B" + "all". |
| 18 | +"FrameBuffer" 可以这样生成:"F" + "rame" + "B" + "uffer". |
| 19 | +.... |
13 | 20 |
|
14 |
| -[subs="verbatim,quotes,macros"] |
15 |
| ----- |
16 |
| -*Input:* queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB" |
17 |
| -*Output:* [true,false,true,true,false] |
18 |
| -*Explanation:* |
19 |
| -"FooBar" can be generated like this "F" + "oo" + "B" + "ar". |
20 |
| -"FootBall" can be generated like this "F" + "oot" + "B" + "all". |
21 |
| -"FrameBuffer" can be generated like this "F" + "rame" + "B" + "uffer". |
22 |
| ----- |
| 21 | +*示例 2:* |
23 | 22 |
|
24 |
| -*Example 2:* |
| 23 | +.... |
| 24 | +输入:queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa" |
| 25 | +输出:[true,false,true,false,false] |
| 26 | +解释: |
| 27 | +"FooBar" 可以这样生成:"Fo" + "o" + "Ba" + "r". |
| 28 | +"FootBall" 可以这样生成:"Fo" + "ot" + "Ba" + "ll". |
| 29 | +.... |
25 | 30 |
|
26 |
| -[subs="verbatim,quotes,macros"] |
27 |
| ----- |
28 |
| -*Input:* queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa" |
29 |
| -*Output:* [true,false,true,false,false] |
30 |
| -*Explanation:* |
31 |
| -"FooBar" can be generated like this "Fo" + "o" + "Ba" + "r". |
32 |
| -"FootBall" can be generated like this "Fo" + "ot" + "Ba" + "ll". |
| 31 | +*示例 3:* |
33 | 32 |
|
34 |
| ----- |
| 33 | +.... |
| 34 | +输入:queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT" |
| 35 | +输出:[false,true,false,false,false] |
| 36 | +解释: |
| 37 | +"FooBarTest" 可以这样生成:"Fo" + "o" + "Ba" + "r" + "T" + "est". |
| 38 | +.... |
35 | 39 |
|
36 |
| -*Example 3:* |
37 | 40 |
|
38 |
| -[subs="verbatim,quotes,macros"] |
39 |
| ----- |
40 |
| -*Input:* queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT" |
41 |
| -*Output:* [false,true,false,false,false] |
42 |
| -*Explanation:* |
43 |
| -"FooBarTest" can be generated like this "Fo" + "o" + "Ba" + "r" + "T" + "est". |
44 |
| -
|
45 |
| ----- |
| 41 | +*提示:* |
46 | 42 |
|
47 |
| - |
48 |
| - |
49 |
| -*Note:* |
50 |
| - |
51 |
| - |
52 |
| -. `1 <= queries.length <= 100` |
53 |
| -. `1 <= queries[i].length <= 100` |
54 |
| -. `1 <= pattern.length <= 100` |
55 |
| -. All strings consists only of lower and upper case English letters. |
| 43 | +* `+1 <= pattern.length, queries.length <= 100+` |
| 44 | +* `+1 <= queries[i].length <= 100+` |
| 45 | +* `queries[i]` 和 `pattern` 由英文字母组成 |
56 | 46 |
|
57 | 47 |
|
| 48 | +== 思路分析 |
58 | 49 |
|
| 50 | +逐个字符去遍历,相同则添加到 `sb` 中,如果不同,是大写就直接返回 `false`,如果是小写就把原字符添加到 `sb` 中。匹配结束,如果 `pattern` 没有到结尾就 `false`。遍历字符串剩余字符,如果有大写字符就判错,否则添加到 `sb`,最后判断 `sb` 和原字符串是否相同。 |
59 | 51 |
|
60 | 52 | [[src-1023]]
|
| 53 | +[tabs] |
| 54 | +==== |
| 55 | +一刷:: |
| 56 | ++ |
| 57 | +-- |
61 | 58 | [{java_src_attr}]
|
62 | 59 | ----
|
63 | 60 | include::{sourcedir}/_1023_CamelcaseMatching.java[tag=answer]
|
64 | 61 | ----
|
| 62 | +-- |
| 63 | +
|
| 64 | +// 二刷:: |
| 65 | +// + |
| 66 | +// -- |
| 67 | +// [{java_src_attr}] |
| 68 | +// ---- |
| 69 | +// include::{sourcedir}/_1023_CamelcaseMatching_2.java[tag=answer] |
| 70 | +// ---- |
| 71 | +// -- |
| 72 | +==== |
| 73 | + |
| 74 | + |
| 75 | +== 参考资料 |
65 | 76 |
|
| 77 | +. https://leetcode.cn/problems/camelcase-matching/solutions/2225856/python3javacgotypescript-yi-ti-yi-jie-sh-vr5x/[1023. 驼峰式匹配 - 一题一解:双指针(清晰题解)^] |
| 78 | +. https://leetcode.cn/problems/camelcase-matching/solutions/2224532/tuo-feng-shi-pi-pei-by-leetcode-solution-pwq7/[1023. 驼峰式匹配 - 官方题解^] |
0 commit comments