zoukankan      html  css  js  c++  java
  • [经典] 回文问题(三)

    Longest Palindromic Substring 最长回文子串

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.

    普通做法,动态规划O(N^2)是能直接出结果的,长度从小到大排列,可以边动规边记录最大值。

    Shortest Palindrome 最短回文生成

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.

    For example:

    Given "aacecaaa", return "aaacecaaa".

    Given "abcd", return "dcbabcd".

    普通做法,即找到从头开始的最长的回文,复杂度为O(N^2);然后补齐。

    事实上,找到以某个点为中心的最长回文子串的经典算法是 Manacher算法,复杂度为O(N),可求出以字符串中各个点为中心的子串。Manacher算法可参考http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/

  • 相关阅读:
    Docker 镜像
    Docker 安装命令
    Docker 基本概念
    Redis 高可用之"持久化"
    Git 安装和使用
    oracle角色
    oracle权限
    审计
    手动创建数据库
    oracle口令文件认证
  • 原文地址:https://www.cnblogs.com/littletail/p/5372747.html
Copyright © 2011-2022 走看看