Palindrome Permutation
Counting Map
http://stackoverflow.com/questions/81346/most-efficient-way-to-increment-a-map-value-in-java
Source code Read on Github
1 public class Solution {
2 public boolean canPermutePalindrome(String s) {
3 Map<Character, Integer> m = new HashMap<>();
4
5 for(char c : s.toCharArray()){
6 Integer i = m.get(c);
7
8 if(i == null){
9 m.put(c, 1);
10 } else {
11 m.put(c, i + 1);
12 }
13 }
14
15 int single = 0;
16
17 for(int v : m.values()){
18 if(v % 2 == 1){
19 single++;
20 }
21
22 if(single > 1){
23 return false;
24 }
25 }
26
27 return true;
28 }
29 }