https://leetcode.com/problems/longest-palindrome/ public class Solution { public int longestPalindrome(String s) { char []charr = s.toCharArray(); Arrays.sort(charr); int result = 0; for (int i=0; i<charr.length; i++) { if (i==charr.length-1) { break; } if (charr[i] == charr[i+1]) { result += 2; i++; } } if (result < charr.length) { result++; } return result; } }