题目来源:
leetcode题目,网址:面试题 01.04. 回文排列 - 力扣(LeetCode)
解题思路:
对字符串中各字符计数,若个数为奇数的字符个数大于 1,则不是回文排列,否则是。
解题代码:
- class Solution {
- public:
- bool canPermutePalindrome(string s) {
- vector<int> cnt(128,0);
- for(int i=0;i<s.length();i++){
- cnt[s[i]]++;
- }
- int odd=0;
- for(int i=0;i<cnt.size();i++){
- if(cnt[i]%2!=0){
- odd++;
- if(odd>1){
- return false;
- }
- }
- }
- return true;
-
- }
- };
总结:
无官方题解。