Counting palindromic substrings in O(n)

后端 未结 3 1526
情书的邮戳
情书的邮戳 2020-12-07 15:01

Given a string (assume only English characters) S of length n, we can count the number of palindromic substrings with the following algorithm:

3条回答
  •  抹茶落季
    2020-12-07 15:29

    The following site shows an algorithm for computing the longest palindromic substring in O(n) time, and does so by computing the longest palindromic substring at every possible center and then taking the maximum. So, you should be able to easily modify it for your purposes.

    http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/

    EDIT: The first link looks a little shaky upon closer inspection, so here's another one:

    http://zhuhcheng.spaces.live.com/Blog/cns!DE38E96268C49F28!311.entry?wa=wsignin1.0&sa=707413829

提交回复
热议问题