Given a string, determine if a permutation of the string could form a palindrome.
For example,
"code" -> False, "aab" -> True, "carerac" -> True.
判断一个字符串的字母排列之后是否能组成回文字符串
很快就做出来了 思路是
回文字符串中的字符都是成对的 最多有一个单独的
但是solution给出了很多实现方式 下面的single pass写的不错
public class Solution {
public boolean canPermutePalindrome(String s) {
int[] map = new int[128];
int count = 0;
for (int i = 0; i < s.length(); i++) {
map[s.charAt(i)]++;
if (map[s.charAt(i)] % 2 == 0)
count--;
else
count++;
}
return count <= 1;
}
}