Algorithms DP-01 LPS
Dynamic Programming Leetcode 5. 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. Example 1: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: "cbbd" Output: "bb" 解题思路 1. 根据回文类型 将回文串分为三种: 第一种是对称式回文串,比如:acddca 第二种是重复式的,比如:aaaaa 第三种是夹心饼干使的:acbbca 针对这三种情况来分析 C代码 2. 马拉车(Maracher)算法 马拉车(Maracher)算法 这道题用c语言的马拉车算法反而更耗时,因为需要频繁地申请内存,可能其他语言会更加高效。 C代码