Palindrome Permutation -- LeetCode
2024-09-02 06:16:01
Given a string, determine if a permutation of the string could form a palindrome.
For example,"code"
-> False, "aab"
-> True, "carerac"
-> True.
要点:学习如何iterate一个unordered_map。
class Solution {
public:
bool canPermutePalindrome(string s) {
unordered_map<char, int> dict;
for (int i = , n = s.size(); i < n; i++) {
if (dict.count(s[i]) == )
dict.insert(make_pair(s[i], ));
else dict[s[i]]++;
}
int oddCount = ;
for (auto it = dict.begin(); it != dict.end(); it++) {
if (it->second % ) oddCount++;
if (oddCount > ) return false;
}
return true;
}
};
最新文章
- ASP.NET MVC Model验证(三)
- Dynamics CRM 2015-如何修改Optionset Default Value
- MontageJS:构建现代 Web App 的 HTML5 框架
- cpg数据库处理_找到未提取的pdf
- 【001:Tomcat搭建简单文件服务器】
- HTTP 头部详细解释
- poj 2236 并查集
- PO_PO系列 - 收货管理分析(案例)
- iOS应用如何支持IPV6-b
- shell基础——变量定义
- innodb更改行格式,系统盘占用急剧升高
- B树和B+树的总结
- Python中使用hashlib进行加密的简单使用
- 3、java面向对象编程
- iOS逆向工程概述(转)
- 十分钟搞定 pandas
- Nginx.conf配置文件参数说明与优化
- 微信小程序之---- 数据处理
- C#泛型的学习
- 2018-2019-2 20175230 实验三《Java面向对象程序设计》实验报告
热门文章
- appium+python的APP自动化(2)
- Ubuntu15.04 python升级到python-3.6.x
- Leetcode 662.二叉树最大宽度
- HDU 4346 The Beautiful Road ( 反向考虑 思路题 )
- UVa 1445 - Cubist Artwork
- iPhone新建项目不能全屏
- Python中的多线程编程,线程安全与锁(一)
- 【bzoj2306】[Ctsc2011]幸福路径 倍增Floyd
- P2029 跳舞
- [洛谷P2634][国家集训队]聪聪可可