266. Palindrome Permutation
Palindrome Permutation
Solution
public class Solution {
public boolean canPermutePalindrome(String s) {
if (s == null || s.length() == 0) return false;
if (s.length() == 1) return true;
Map<Character, Integer> map = new HashMap<>();
for (char c : s.toCharArray()) {
map.merge(c, 1, (a, b) -> a + b);
}
int oddCount = 0;
for(Character key: map.keySet()) {
if (map.get(key) % 2 == 1) {
oddCount +=1;
}
}
if (oddCount > 1) {
return false;
} else {
return true;
}
}
}Last updated