public String longestPalindromeExpandAroundCenter(String s) { if (s == null || s.length() < 1) { return""; } intstart=0, end = 0; for (inti=0; i < s.length(); i++) { intlen1= expandAroundCenter(s, i, i); intlen2= expandAroundCenter(s, i, i + 1); intlen= Math.max(len1, len2); if (len > end - start) { start = i - (len - 1) / 2; end = i + len / 2; } } return s.substring(start, end + 1); }
privateintexpandAroundCenter(String s, int left, int right) { while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) { left--; right++; } return right - left - 1; }