首页 \ 问答 \ 什么时候使用KMP算法好?(When is good to use KMP algorithm?)

什么时候使用KMP算法好?(When is good to use KMP algorithm?)

我知道KMP算法依赖于辅助数组,前缀类似于后缀。 当不满足上述条件时,它将无效,因为辅助数组中包含全零。 运行时是否为O(m + n)? 如果我是对的,在这种情况下什么是更好的子串算法?


I understand that KMP algorithm depends on the helper array that there are prefixes that are similar to suffixes. It won't efficient when the above condition is not fulfilled as in the helper array contains all zeroes. Would the runtime be O(m + n) ? If I am right, what is a better substring algorithm in this case?


原文:
更新时间:2022-12-03 11:12

最满意答案

gedit ubuntu

搜索: (.*?)\n(.*?)\n(.*)\n
替换为: \1\n\2\n


gedit ubuntu

Search for: (.*?)\n(.*?)\n(.*)\n
Replace with: \1\n\2\n

相关问答

更多
  • 我认为尝试使用Notepad ++是一个奇怪的想法,但我喜欢挑战,所以我决定给它一个旋转。 打开替换菜单,在“查找内容”框中填写([^\n]*\n)[^\n]*\n ,在“替换为”框中填写$1 。 然后选择搜索模式的正则表达式,点击全部替换,每一行都被删除。 如果你想做类似的事情,你可以创建类似的正则表达式。 例如,如果用n - 1和[^\n]*\n([^\n]*\n)替换n,则(([^\n]*\n){a})[^\n]*\n [^\n]*\n([^\n]*\n)会让你保持连线而不是奇数。 (这根本不难 - ...
  • 您可以在模式内使用子例程调用来递归{...}子模式: "hours":\s*(\{(?>[^{}]++|(?1))*\}) 查看正则表达式演示 模式说明: "hours": - 文字顺序“小时”: \s* - 零个或多个空格 (\{(?>[^{}]++|(?1))*\}) - 将使用(?1)子例程调用递归的组1(因此,将确保递归)。 这将匹配{ ,然后是{和}以外的一个或多个字符或整个组1的子表达式(使用(?1) ),然后匹配} 。 You can use a subroutine call inside ...
  • 您也可以使用Ctrl+alt 。 按Ctrl + Alt拖动数字,然后删除 You can use Ctrl+alt also. Drag the numbers by holding Ctrl + Alt, then delete
  • 找: ^[#;].* 没有任何替换 ^表示一行的开始, [#;]是一个符合#或; ,和.*匹配行中的其他任何东西。 在6.0之前的Notepad ++版本中,由于正则表达式引擎的限制,您将无法实际删除该行; 每行匹配的空白行的替换结果。 换句话说,这个: # foo ; bar statement; 会变成: statement; 但是,如果将\r , \n或\r\n到模式的末尾,则取决于文件正在使用的行,替换将在Notepad ++ 6.0中工作,从而导致: statement; Find: ^[ ...
  • 正则表达式101 .*\n.*\nLINE 5 描述 .* matches any character (except for line terminators) * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy) \n matches a line-feed (newline) character (ASCII 10) .* ...
  • 在Find对话框的Mark选项卡上,您可以为符合的行添加书签...然后在菜单上Search > Bookmark > Remove Unmarked Lines或Remove Bookmarked lines In the Find dialog, on the Mark tab, you can bookmark lines that match... Then on the menu Search > Bookmark > Remove Unmarked Lines or Remove Bookmark ...
  • 这个解决方案有点复杂,可以完全用notepad ++来完成 确保安装了HTML标记插件。 这可以通过进入插件>插件管理器>显示插件管理器,选择名为HTML标签的插件并安装它(如果你还没有)来完成。 或者从这里下载手动安装 将文本光标放在要删除的标记的开始或结束标记上,然后按CTRL + SHIFT + T. 这将选择整个元素及其所有子元素 按CTRL + H以显示查找和替换窗口。 - >选择正则表达式模式, - >确保选中“选择中”, - >在'查找内容'文本框中使用表达式(?s)\A<[^>]*>(.*? ...
  • 确保为搜索模式选择正则表达式 ... 此外,您可能希望将最终换行设置为可选 。 如果行数为偶数且您没有尾随换行符,则不会删除最后一行。 ([^\n]*\n)[^\n]*\n? 更新: 了解Windows如何使用\r\n而不是\r\n来处理新行 。 尝试更新表达式以将此考虑在内: ([^\r\n]*[\r\n]+)[^\r\n]*[\r\n]* 最后更新: 感谢@ zx81,我现在知道N ++使用PCRE所以\R可以用于unicode换行符。 但是[^\R]不起作用(这样可以查找除R之外的任何内容),因此 ...
  • 尝试这个: 找什么: ^(.*) / \1 - (.*)$ 用。。。来代替: \1 - \2 搜索模式:正则表达式 说明: 我们匹配行开头(^)和“/”之间的所有内容并将其放入组1中(通过使用括号) 然后重复第1组中匹配的任何内容(\ 1) 其次是 ” - ” 然后我们将所有内容放到第2行的末尾(通过使用第二对括号) 在替换字符串中,我们引用组1和2,因此如果文件夹部分出现在文件名部分中,则省略文件夹部分。 Try this: Find what: ^(.*) / \1 - (.*)$ Replace wi ...
  • gedit ubuntu 搜索: (.*?)\n(.*?)\n(.*)\n 替换为: \1\n\2\n gedit ubuntu Search for: (.*?)\n(.*?)\n(.*)\n Replace with: \1\n\2\n

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)