266. Palindrome Permutation
Input: "code"
Output: falseInput: "aab"
Output: trueInput: "carerac"
Output: truebool canPermutePalindrome(string s) { // time: O(n); space: O(1)
if (s.empty()) return false;
vector<int> record(128, 0);
for (char c : s) ++record[c];
int odd = 0;
for (int num : record) {
if (num & 1) ++odd;
if (odd > 1) return false;
}
return true;
}Last updated