PU Palindrome Permutation

Jan 01, 1970

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

Example:

  • "code" -> False, "aab" -> True, "carerac" -> True.

C Solution:

bool canPermutePalindrome(char* s) {
    int flag[256] = {0};
    int res = 0;
    for (; *s; s++) {
        if (flag[*s]) {
            res--;
            flag[*s] = 0;
        }
        else {
            res++;
            flag[*s] = 1;
        }
    }
    return res < 2;
}

Summary:

  1. nothing special.
  2. 0ms, 0%

LeetCode: 266. Palindrome Permutation