Skip to content

Commit 23cee80

Browse files
committed
一刷1023
1 parent f3fd97f commit 23cee80

File tree

5 files changed

+124
-50
lines changed

5 files changed

+124
-50
lines changed

README.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7187,13 +7187,13 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
71877187
|Easy
71887188
|
71897189

7190-
//|{counter:codes}
7191-
//|{leetcode_base_url}/camelcase-matching/[1023. Camelcase Matching^]
7192-
//|{source_base_url}/_1023_CamelcaseMatching.java[Java]
7193-
//|{doc_base_url}/1023-camelcase-matching.adoc[题解]
7194-
//|Medium
7195-
//|
7196-
//
7190+
|{counter:codes}
7191+
|{leetcode_base_url}/camelcase-matching/[1023. Camelcase Matching^]
7192+
|{source_base_url}/_1023_CamelcaseMatching.java[Java]
7193+
|{doc_base_url}/1023-camelcase-matching.adoc[题解]
7194+
|Medium
7195+
|
7196+
71977197
//|{counter:codes}
71987198
//|{leetcode_base_url}/video-stitching/[1024. Video Stitching^]
71997199
//|{source_base_url}/_1024_VideoStitching.java[Java]

docs/1023-camelcase-matching.adoc

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,78 @@
11
[#1023-camelcase-matching]
2-
= 1023. Camelcase Matching
2+
= 1023. 驼峰式匹配
33

4-
{leetcode}/problems/camelcase-matching/[LeetCode - Camelcase Matching^]
4+
https://leetcode.cn/problems/camelcase-matching/[LeetCode - 1023. 驼峰式匹配 ^]
55

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`
77

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]`,那么待查询项与给定模式串匹配。可以在任何位置插入每个字符,也可以不插入字符。
99

10-
10+
*示例 1:*
1111

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+
....
1320

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:*
2322

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+
....
2530

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:*
3332

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+
....
3539

36-
*Example 3:*
3740

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+
*提示:*
4642

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` 由英文字母组成
5646
5747
48+
== 思路分析
5849

50+
逐个字符去遍历,相同则添加到 `sb` 中,如果不同,是大写就直接返回 `false`,如果是小写就把原字符添加到 `sb` 中。匹配结束,如果 `pattern` 没有到结尾就 `false`。遍历字符串剩余字符,如果有大写字符就判错,否则添加到 `sb`,最后判断 `sb` 和原字符串是否相同。
5951

6052
[[src-1023]]
53+
[tabs]
54+
====
55+
一刷::
56+
+
57+
--
6158
[{java_src_attr}]
6259
----
6360
include::{sourcedir}/_1023_CamelcaseMatching.java[tag=answer]
6461
----
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+
== 参考资料
6576

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. 驼峰式匹配 - 官方题解^]

docs/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ include::1020-number-of-enclaves.adoc[leveloffset=+1]
21292129

21302130
include::1022-sum-of-root-to-leaf-binary-numbers.adoc[leveloffset=+1]
21312131

2132-
// include::1023-camelcase-matching.adoc[leveloffset=+1]
2132+
include::1023-camelcase-matching.adoc[leveloffset=+1]
21332133

21342134
// include::1024-video-stitching.adoc[leveloffset=+1]
21352135

logbook/202503.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,10 @@ endif::[]
878878
|{doc_base_url}/0865-smallest-subtree-with-all-the-deepest-nodes.adoc[题解]
879879
|✅ 深度优先遍历,递归,在“后序”阶段处理业务逻辑。
880880

881+
|{counter:codes2503}
882+
|{leetcode_base_url}/camelcase-matching/[1023. 驼峰式匹配^]
883+
|{doc_base_url}/1023-camelcase-matching.adoc[题解]
884+
|✅ 双指针
881885

882886
|===
883887

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.diguage.algo.leetcode;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _1023_CamelcaseMatching {
7+
// tag::answer[]
8+
9+
/**
10+
* @author D瓜哥 · https://www.diguage.com
11+
* @since 2025-05-31 20:11:57
12+
*/
13+
public List<Boolean> camelMatch(String[] queries, String pattern) {
14+
List<Boolean> result = new ArrayList<>(queries.length);
15+
for (int i = 0; i < queries.length; i++) {
16+
result.add(isMatch(queries[i], pattern));
17+
}
18+
return result;
19+
}
20+
21+
private boolean isMatch(String query, String pattern) {
22+
char[] chars = pattern.toCharArray();
23+
int m = 0, n = 0;
24+
StringBuilder sb = new StringBuilder(query.length());
25+
while (m < query.length() && n < chars.length) {
26+
char mc = query.charAt(m);
27+
char nc = chars[n];
28+
if (mc == nc) {
29+
m++;
30+
n++;
31+
sb.append(nc);
32+
} else if (Character.isUpperCase(mc)) {
33+
return false;
34+
} else {
35+
sb.append(mc);
36+
m++;
37+
}
38+
}
39+
if (n < chars.length) {
40+
return false;
41+
}
42+
for (int i = m; i < query.length(); i++) {
43+
char mc = query.charAt(i);
44+
if (Character.isUpperCase(mc)) {
45+
return false;
46+
}
47+
sb.append(mc);
48+
}
49+
return query.equals(sb.toString());
50+
}
51+
// end::answer[]
52+
53+
public static void main(String[] args) {
54+
new _1023_CamelcaseMatching().camelMatch(
55+
new String[]{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, "FoBa");
56+
}
57+
}

0 commit comments

Comments
 (0)