Palindrome Permutation
来源:互联网 发布:电脑版进库出库软件 编辑:程序博客网 时间:2024/06/05 13:22
Given a string, determine if a permutation of the string could form a palindrome.
For example,
"code"
-> False, "aab"
-> True, "carerac"
-> True.
思路:count 奇偶性,把握Palindrome的特性,全部是偶数对,最多只有一个奇数.
public class Solution { public boolean canPermutePalindrome(String s) { if(s == null ) return false; if(s.length() ==0) return true; HashMap<Character, Integer> hashmap = new HashMap<Character, Integer>(); for(int i=0; i<s.length(); i++){ char c = s.charAt(i); Integer val = hashmap.get(c); if(val == null){ hashmap.put(c,1); } else { hashmap.put(c,val+1); } } int count = 0; for(Integer val : hashmap.values()){ if(val%2 == 1){ count++; } } return count<=1; } }
0 0
- Palindrome Permutation
- Palindrome Permutation
- Palindrome Permutation
- Leetcode: Palindrome Permutation
- *LeetCode-Palindrome Permutation
- [LeetCode 266]Palindrome Permutation
- 1.4 Palindrome Permutation
- 266 Palindrome Permutation
- [LeetCode266]Palindrome Permutation
- [LeetCode267]Palindrome Permutation II
- Leetcode - 266. Palindrome Permutation
- Leetcode266 Palindrome Permutation
- [Leetcode 266] Palindrome Permutation
- LeetCode 266. Palindrome Permutation
- Palindrome Permutation II
- 266. Palindrome Permutation
- Palindrome Permutation II
- Palindrome Permutation II
- 安卓学习笔记(四)Button监听
- Python股票历史数据下载
- Java股票数据下载
- HDU2057 A + B Again
- win10系统每天凌晨3点左右,自动关机重启
- Palindrome Permutation
- JavaScript事件使用指南
- Remove Duplicates from Sorted Array
- SQL中的left outer join,inner join,right outer join用法
- 设计模式(3)-结构型-代理模式(proxy)以及java动态代理的两种方式
- hive的查询注意事项以及优化总结 .
- SQL中declare申明变量
- SQL中declare申明变量
- Windows驱动开发之驱动开发环境搭建