(String s)
| 1 | public class Solution { |
| 2 | // example in leetcode book |
| 3 | public String longestPalindrome(String s) { |
| 4 | int start = 0, end = 0; |
| 5 | for (int i = 0; i < s.length(); i++) { |
| 6 | // aba |
| 7 | int len1 = expandAroundCenter(s, i, i); |
| 8 | // bb |
| 9 | int len2 = expandAroundCenter(s, i, i + 1); |
| 10 | int len = Math.max(len1, len2); |
| 11 | if (len > end - start) { |
| 12 | start = i - (len - 1) / 2; |
| 13 | end = i + len / 2; |
| 14 | } |
| 15 | } |
| 16 | return s.substring(start, end + 1); |
| 17 | } |
| 18 | |
| 19 | private int expandAroundCenter(String s, int left, int right) { |
| 20 | int L = left, R = right; |
nothing calls this directly
no test coverage detected