方法一:时间复杂度为O(n^3) public static String longestPalindrome1(String s) {int maxPalinLength = 0;String longestPalindrome = null;int length = s.length();// check all possible sub stringsfor (int i = 0; i
1297. Palindrome Time Limit: 1.0 second Memory Limit: 16 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlim
R7-多维dp篇 思路: 两种情况,中心1个数,中心2个数 大体:中间点扩展原则 class Solution:def expand(self,s,left,right):while left>=0 and right<len(s) and s[left]==s[right]:left-=1right+=1#不满足就回退return left+1,right-1def longe
题目链接 我的题解(双指针) 思路: 当然,以下是对您提供的代码的解释: class Solution {public int countSubstrings(String s) {// 初始化回文子字符串的数量int count = 0;// 遍历字符串的每个字符,使用索引 ifor(int i = 0; i < s.length(); i++){// 初始化两个指针 left 和 ri