classSolution{ int lo = 0, hi = 0, maxLen = 0; public String longestPalindrome(String s){ if (s == null || s.length() == 0) { return s; } for (int i = 0; i < s.length(); i++) { expand(s, i, i); expand(s, i, i + 1); } return s.substring(lo, hi + 1); } privatevoidexpand(String s, int i, int j){ while(i >= 0 && j < s.length() && s.charAt(i) == s.charAt(j)) { i--; j++; } if (j - i - 1 > maxLen) { lo = i + 1; hi = j - 1; maxLen = j - i - 1; } } }