Palindrome Permutation
2016-07-24 04:47
246 查看
public class Solution { public boolean canPermutePalindrome(String s) { if (s == null || s.length() < 2) { return true; } Map<Character, Boolean> map = new HashMap<>(); int oddCount = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (!map.containsKey(c)) { map.put(c, false); oddCount++; } else { if (map.get(c)) { map.put(c, false); oddCount++; } else { map.put(c, true); oddCount--; } } } boolean evenStr = s.length() % 2 == 0; if (evenStr) { if (oddCount == 0) { return true; } else { return false; } } else { if (oddCount == 1) { return true; } else { return false; } } } }
相关文章推荐
- Min Stack
- Burst Balloons
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Flex布局
- 【慕课学习】《JavaScript深入浅出》——语句
- Reverse Vowels of a String
- 用vbs 将有序文件转换为有序文件
- HTML5网页新风格总结(与html4对比)
- 一个小玩意引起的反思
- 基于内容的推荐(第二周)
- jquery中each的三种遍历方法
- 开始使用Gulp
- Meeting Rooms
- Meeting Rooms
- 网站性能测试工具ab学习
- 打印一个N*N的方阵,N为每边字符的个数,要求最外层为“X”,第二层为“Y”,从第三层起每层依次打印数字0,1,2,3,...
- TensorFlow安装教程与Android Camera Demo示例(Ubuntu Trusty 14.04 LTS)
- 海贼王 手游 自己搭建自娱自乐
- 写在最开始,写给自己