Palindrome Permutation

Source

  • leetcode: 266
Given a string, determine if a permutation of the string could form a palindrome.
For example, "code" -> False, "aab" -> True, "carerac" -> True.

Java

//http://www.meetqun.com/thread-10670-1-1.html
//http://likesky3.iteye.com/blog/2237297

public boolean canPermutePalindrome1(String s) {  
    int[] map = new int[256];  
    for (int i = 0; i < s.length(); i++) {  
        map[s.charAt(i)]++;  
    }  
    int oddOccurCounter = 0;  
    for (int i = 0; i < 256; i++) {  
        if ((map[i])%2) == 1)  
            oddOccurCounter++;  
    }  
    if ((s.length()%2) == 1)  
        return oddOccurCounter == 1;  
    else  
        return oddOccurCounter == 0;  
}