0266. Palindrome Permutation
Description
**Input:** s = "code"
**Output:** false**Input:** s = "aab"
**Output:** true**Input:** s = "carerac"
**Output:** trueac
Last updated
**Input:** s = "code"
**Output:** false**Input:** s = "aab"
**Output:** true**Input:** s = "carerac"
**Output:** trueLast updated
class Solution {
public boolean canPermutePalindrome(String s) {
// edge cases
if (s.length() <= 1) return true;
Map<Character, Integer> map = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
map.put(c, map.getOrDefault(c, 0) + 1);
}
boolean oddFound = false;
for (char k : map.keySet()) {
int val = map.get(k);
if (val % 2 == 1) {
if (oddFound) return false;
else oddFound = true;
}
}
return true;
}
}