当前位置:网站首页>程序员面试金典面试题 01.04. 回文排列
程序员面试金典面试题 01.04. 回文排列
2022-07-22 09:24:00 【yijun009】
class Solution {
public:
bool canPermutePalindrome(string s) {
int l = s.length();
if ((l==2)&&(s[0]!=s[1])) return false;
std::map<char,int> mymap;
for (int i =0;i<l;i++) mymap[s[i]]=0;
for (int i =0;i<l;i++) mymap[s[i]]++;
int count_odd=0;
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it){
if (it->second%2==1) count_odd++;
}
if (count_odd>1) return false;
return true;
}
};
C++ 字典 map,遍历字典中的元素的时候,小心要不要用key来遍历。写的程序和想法并不一致。
边栏推荐
猜你喜欢
随机推荐
LeetCode 693. 交替位二进制数
Leetcode 693. alternating bit binary number
webFlux 中使用 openFeign 实现远程调用遇到的问题
在各類數據庫中隨機查詢n條數據
Leetcode 2039. when the network is idle
LeetCode 654. 最大二叉树
MySQL的语句执行顺序
预算dll要达到的效果,Qt将第三方窗口嵌入程序内,excel操作,数据库外键,判断程序是否启动
The database is garbled. Do you want to find a solution?
1. Closeable of qtablewidget, 2.pro/build_ pass、member,3.QString&&
Parameter index out of range (1 &gt; number of parameters, which is 0).
PAT乙级1019 数字黑洞 (20 分) (测点错误可能原因)
LeetCode: 185. 部门工资前三高的所有员工
PTA basic question 7-23 currency conversion (20 points) (true)
数据优化的方式
PTA basic questions 7-28 monkeys choose the king (simple method)
Leetcode 105. constructing binary trees from preorder and inorder traversal sequences
pytorch自定义dataloder的时候,返回参数
Vlfeat, pydot configuration
Practice 7-7 matrix operation (20 points)