面试题 01.04. 回文排列

​​题目来源:

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;

    }
};
复制代码

总结:

无官方题解。


相关推荐
设计师小聂!7 小时前
力扣热题100------21.合并两个有序链表
算法·leetcode·链表
এ᭄画画的北北7 小时前
力扣-1.两数之和
数据结构·算法·leetcode
清朝牢弟8 小时前
Ubuntu系统VScode实现opencv(c++)图像像素类型转换和归一化
c++·opencv·ubuntu
黑色的山岗在沉睡8 小时前
P1948 [USACO08JAN] Telephone Lines S
数据结构·c++·算法·图论
快去睡觉~9 小时前
力扣301:删除无效的括号
数据结构·算法·leetcode
玖剹10 小时前
Linux文件操作:从C接口到系统调用
linux·服务器·c语言·c++·笔记·ubuntu
ikkkkkkkl11 小时前
LeetCode:15.三数之和&&18.四数之和
c++·算法·leetcode
pusue_the_sun11 小时前
从零开始搞定类与对象(中)
开发语言·c++·学习
屁股割了还要学12 小时前
【数据结构入门】链表
c语言·开发语言·数据结构·c++·学习·算法·链表
君鼎12 小时前
Effective C++ 条款19: 设计class犹如设计type
c++