名称: 字符串算法匹配器
描述: 将字符串问题匹配到合适的算法
允许工具:
字符串算法匹配器技能
目的
根据需求和约束条件,将字符串处理问题匹配到最合适的算法。
能力
- 模式匹配算法选择(KMP、Z、Rabin-Karp)
- 后缀结构选择(数组 vs 树 vs 自动机)
- 回文检测算法选择
- 滚动哈希实现指导
- 字符串动态规划技术匹配
目标流程
算法选择指南
单模式匹配
| 场景 |
算法 |
复杂度 |
| 单模式 |
KMP |
O(n+m) |
| 多模式 |
Aho-Corasick |
O(n+m+z) |
| 近似匹配 |
滚动哈希 |
O(n*m) 平均 |
后缀结构
| 需求 |
结构 |
构建时间 |
| 子串搜索 |
后缀数组 |
O(n log n) |
| 多查询 |
后缀树 |
O(n) |
| 子序列计数 |
后缀自动机 |
O(n) |
回文
| 问题 |
算法 |
| 最长回文子串 |
Manacher |
| 回文分割 |
动态规划 + Manacher |
| 回文查询 |
哈希 |
输入模式
{
"type": "object",
"properties": {
"problemDescription": { "type": "string" },
"problemType": {
"type": "string",
"enum": ["patternMatch", "suffixQueries", "palindrome", "subsequence", "dp"]
},
"constraints": { "type": "object" }
},
"required": ["problemDescription"]
}
输出模式
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"algorithm": { "type": "string" },
"complexity": { "type": "string" },
"alternatives": { "type": "array" },
"implementation": { "type": "string" }
},
"required": ["success", "algorithm"]
}