https://leetcode.com/problems/palindrome-permutation/
Given a string, determine if a permutation of the string could form a palindrome.
For example,
"code"
-> False, "aab"
-> True, "carerac"
-> True.
public class Solution {
public boolean canPermutePalindrome(String s) {
char[] c = s.toCharArray();
int[] i = new int[128];
for(char cc: c){
i[(int) cc]+=1;
}
boolean flag = true;
for(int ii: i){
if(ii%2!=0){
if(flag) flag=false;
else return false;
}
}
return true;
}
}
Only at most one character's occurrence can be odd. Suppose charset is ASCII