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:
- nothing special.
- 0ms, 0%
LeetCode: 266. Palindrome Permutation





近期评论