[LeetCode]Word Break
public class Solution { public String longestPalindrome(String s) { int length = s.length(); String result = ""; for (int i = 0; i < length; i++) { int left = i; int right = i; while (right + 1 < length && s.charAt(right) == s.charAt(right + 1)) { right ++; } while (left > 0 && right + 1 < length && s.charAt(left - 1) == s.charAt(right + 1)) { left --; right ++; } result = right - left + 1 > result.length() ? s.substring(left, right + 1) : result; } return result; } }