730. 统计不同回文子字符串 给定一个字符串 S,找出 S 中不同的非空回文子序列个数,并返回该数字与 10^9 + 7 的模. 通过从 S 中删除 0 个或多个字符来获得子字符序列. 如果一个字符序列与它反转后的字符序列一致,那么它是回文字符序列. 如果对于某个 i,A_i != B_i,那么 A_1, A_2, - 和 B_1, B_2, - 这两个字符序列是不同的. 示例 1: 输入: S = 'bccb' 输出:6 解释: 6 个不同的非空回文子字符序列分别为:'b', 'c', 'b…
Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters. Example 1: Input: "abc" Ou…
Given a string S, find the number of different non-empty palindromic subsequences in S, and return that number modulo 10^9 + 7. A subsequence of a string S is obtained by deleting 0 or more characters from S. A sequence is palindromic if it is equal…
题目链接 https://leetcode-cn.com/problems/count-different-palindromic-subsequences/ 题意 给定一个字符串,判断这个字符串中所有的回文子序列的个数.注意回文子序列不一定连续,可以删除某些字符得到.重复的回文字符串只计算一次. 思路: 动态规划,难点: 回文字符串怎么判重 动态规划的转移方程怎么推导 在这里我们假设dp[i][j]表示从[i,..,j]字符串中含有的不重复回文字符串的总数,那么首先来看边界条件: 如果每个字符…
Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters. Example 1: Input: "abc" Ou…
class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return true; //单个字符,对称 char *p,*q; p=&s[]; //p指向开头 q=&s[s.length()-]; //q指向末尾 while(p!=q){ //测试字符串里是否有字母或数字,若没有,则立刻返回 '&&*p<'A') || (*p>'Z'&…
5. 最长回文子串 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab" 注意: "aba" 也是一个有效答案. 示例 2: 输入: "cbbd" 输出: "bb" 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/longest-palindromic-subs…
516. 最长回文子序列 给定一个字符串s,找到其中最长的回文子序列.可以假设s的最大长度为1000. 示例 1: 输入: "bbbab" 输出: 4 一个可能的最长回文子序列为 "bbbb". 示例 2: 输入: "cbbd" 输出: 2 一个可能的最长回文子序列为 "bb". PS: 动态规划, 第一个就不多说了,dp[i][j]就是截取后i位,然后挨着截取后i位的第j位 相等就+2,不相等找[i+1][j]和[i][j-…
409. 最长回文串 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串. 在构造过程中,请注意区分大小写.比如 "Aa" 不能当做一个回文字符串. 注意: 假设字符串的长度不会超过 1010. 示例 1: 输入: "abccccdd" 输出: 7 解释: 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7. class Solution { public int longestPalindrome(Str…
给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad"输出: "bab"注意: "aba" 也是一个有效答案. 示例 2: 输入: "cbbd"输出: "bb" 来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/longest-palindromic-substring 方法1:动态规划…