Problem
Given a string, determine if a permutation of the string could form a palindrome.
Example 1:
Input: "code"
Output: false
Example 2:
Input: "aab"
Output: true
Example 3:
Input: "carerac"
Output: true
Solution
class Solution {
public boolean canPermutePalindrome(String s) {
Set<Character> set = new HashSet<>();
for (char ch: s.toCharArray()) {
if (set.contains(ch)) set.remove(ch);
else set.add(ch);
}
return set.size() <= 1;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。