标签:return rom substring i++ har public java ges long
public String longestPalindrome(String s) {
String rs = "";
int res = 0;
for(int i = 0; i< s.length(); i++){
int left = i, right = i;
while(left >= 0 && s.charAt(i) == s.charAt(left)) left --;
while(right < s.length() && s.charAt(i) == s.charAt(right)) right ++;
while (left >= 0 && right < s.length()){
if (s.charAt(left) != s.charAt(right))
break;
left --; right ++ ;
}
if(right - left - 1 > res){
res = right - left - 1;
rs = s.substring(left+1, right);
}
}
return rs;
}
leetcode 5. Longest Palindromic Substring [java]
标签:return rom substring i++ har public java ges long
原文地址:https://www.cnblogs.com/whyaza/p/10661298.html