Palindrome Permutation
给一个字符串, 问他的随意组合能否组成一个回文. 回文就是里面的字符是偶数或者只有一个奇数.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
class Solution { public boolean canPermutePalindrome(String s) { int[] count = new int[512]; for(char c : s.toCharArray()) { count[c] ++; } int odd = 0; for(int n : count){ if(n % 2 != 0) odd++; } return odd <= 1; } } |