longest-palindrome

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;
    }
}

 

posted @ 2016-10-03 21:35  blcblc  阅读(247)  评论(0编辑  收藏  举报