Given a string, determine if a permutation of the string could form a palindrome.
For example,"code"
-> False,"aab"
-> True,"carerac"
-> True.
class Solution {
public boolean canPermutePalindrome(String s) {
if (s == null || s.length() == 0) return true;
int[] hash = new int[256];
for (char c : s.toCharArray()){
if (!Character.isLetter(c)) continue;
hash[c]++;
}
boolean hasOdd = false;
for (int i = 0; i < 256; i++){
if (hash[i] > 0){
if (hash[i] % 2 == 0) continue;
if (!hasOdd){
hasOdd = true;
}
else{
return false;
}
}
}
return true;
}
}