Palindrome Permutation
Source
Given a string, determine if a permutation of the string could form a palindrome.
For example, "code" -> False, "aab" -> True, "carerac" -> True.
Java
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;
}