class Solution {
public String longestPalindrome(String s) {
int resL = 0, resR = 0;
int resLen = resR - resL + 1;
for (int i = 0; i < s.length(); ++i) {
int l = i, r = i;
while (inBound(r, l, s) && s.charAt(l) == s.charAt(r)) {
if (resLen < (r - l + 1)) {
resL = l;
resR = r;
resLen = r - l + 1;
}
--l;
++r;
}
l = i;
r = i + 1;
while (inBound(r, l, s) && s.charAt(l) == s.charAt(r)) {
if (resLen < (r - l + 1)) {
resL = l;
resR = r;
resLen = r - l + 1;
}
--l;
++r;
}
}
return s.substring(resL, resR + 1);
}
private boolean inBound(int r, int l, String s) {
return l >= 0 && r < s.length();
}
}