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;
}
};

Palindrome Permutation -- LeetCode的更多相关文章

  1. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  2. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  3. LeetCode Palindrome Permutation II

    原题链接在这里:https://leetcode.com/problems/palindrome-permutation-ii/ 题目: Given a string s, return all th ...

  4. LeetCode Palindrome Permutation

    原题链接在这里:https://leetcode.com/problems/palindrome-permutation/ 题目: Given a string, determine if a per ...

  5. [LeetCode] 266. Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. Example 1: Input: ...

  6. [LeetCode] 267. Palindrome Permutation II 回文全排列 II

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  7. [LeetCode#267] Palindrome Permutation II

    Problem: Given a string s, return all the palindromic permutations (without duplicates) of it. Retur ...

  8. [LeetCode] Palindrome Permutation I & II

    Palindrome Permutation Given a string, determine if a permutation of the string could form a palindr ...

  9. leetcode 266.Palindrome Permutation 、267.Palindrome Permutation II

    266.Palindrome Permutation https://www.cnblogs.com/grandyang/p/5223238.html 判断一个字符串的全排列能否形成一个回文串. 能组 ...

随机推荐

  1. Leetcode 659.分割数组为连续子序列

    分割数组为连续子序列 输入一个按升序排序的整数数组(可能包含重复数字),你需要将它们分割成几个子序列,其中每个子序列至少包含三个连续整数.返回你是否能做出这样的分割? 示例 1: 输入: [1,2,3 ...

  2. 【bzoj2506】calc 根号分治+STL-vector+二分+莫队算法

    题目描述 给一个长度为n的非负整数序列A1,A2,…,An.现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且Ai mod p = k的值i的个数. 输入 第一行两个正整数n ...

  3. JAVA判断一个字符串里面有没有汉字

    private static boolean checkIfExistChineseCharacter(String s) { return !(s.length() == s.getBytes(). ...

  4. POJ 3041 Asteroids | 匈牙利算法模板

    emmmmm 让你敲个匈牙利 #include<cstdio> #include<algorithm> #include<cstring> #define N 51 ...

  5. 性能优化-使用 RAIL 模型评估性能

    RAIL 是一种以用户为中心的性能模型.每个网络应用均具有与其生命周期有关的四个不同方面,且这些方面以不同的方式影响着性能: TL;DR 以用户为中心:最终目标不是让您的网站在任何特定设备上都能运行很 ...

  6. 让JS帮你决定午餐吃什么吧

    最愁就是每天中午吃什么了,有空就做了个 JavaScript 轮播随机选择.会轮播预先自定义的菜单中,然后点选定的时候确定一款.代码可以查看本页源代码获得,你可以自定义修改菜单数组. 效果演示 准备选 ...

  7. ZJUTACM

    描述 这回是浙江工业大学的ACM程序设计竞赛,欢迎你的到来!但是,请稍等!裁判Joe说了,必须正确回答他的问题,才可以看到PIPI的气球MM,KUKU的气球GG.Joe手上有7张卡片,每张卡片上有一个 ...

  8. Codeforces Round #462 (Div. 2)

    这是我打的第三场cf,个人的表现还是有点不成熟.暴露出了我的一些问题. 先打开A题,大概3min看懂题意+一小会儿的思考后开始码代码.一开始想着贪心地只取两个端点的值就好了,正准备交的时候回想起上次A ...

  9. ztree 2.0 节点搜索

    最近做了一个简单的功能,树节点的搜索.ztree的版本的2.0,3.X以上的版本请百度解决办法. 1.在setting中增加 function getFontCss(treeId, treeNode) ...

  10. 模拟Json格式传值请求与数据接收

    a.php代码: function http_post_json($url, $jsonStr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, ...