# 266. Palindrome Permutation

Given a string, determine if a permutation of the string could form a palindrome.

**Example 1:**

```cpp
Input: "code"
Output: false
```

**Example 2:**

```cpp
Input: "aab"
Output: true
```

**Example 3:**

```cpp
Input: "carerac"
Output: true
```

```cpp
bool 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;
}
```

```cpp
bool canPermutePalindrome(string s) { // time: O(n); space: O(1)
    unordered_set<char> hashset;
    for (char c : s) {
        if (!hashset.count(c)) hashset.insert(c);
        else hashset.erase(c);
    }
    return hashset.size() <= 1;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jimmylin1991.gitbook.io/practice-of-algorithm-problems/string/266.-palindrome-permutation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
