package com.fishercoder.solutions;

import java.util.HashMap;
import java.util.Map;

/**Given a string, determine if a permutation of the string could form a palindrome.

 For example,
 "code" -> False, "aab" -> True, "carerac" -> True.

 Hint:

 Consider the palindromes of odd vs even length. What difference do you notice?
 Count the frequency of each character.
 If each character occurs even number of times, then it must be a palindrome. How about character which occurs odd number of times?*/
public class _266 {

    public boolean canPermutePalindrome(String s) {

        char[] chars = s.toCharArray();
        Map<Character, Integer> map = new HashMap<Character, Integer>();
        for (char c : chars) {
            if (!map.containsKey(c)) {
                map.put(c, 1);
            } else {
                map.put(c, map.get(c) + 1);
            }
        }
        int evenCount = 0;
        for (Map.Entry<Character, Integer> e : map.entrySet()) {
            if (e.getValue() % 2 != 0) {
                evenCount++;
            }
            if (evenCount > 1) {
                return false;
            }
        }
        return true;

    }

}

@@ -82,444 +82,69 @@
 p;%0A%0A
-/**Given a string, determine if a permutation of the string could form a palindrome.%0A%0A For example,%0A %22code%22 -%3E False, %22aab%22 -%3E True, %22carerac%22 -%3E True.%0A%0A Hint:%0A%0A Consider the palindromes of odd vs even length. What difference do you notice?%0A Count the frequency of each character.%0A If each character occurs even number of times, then it must be a palindrome. How about character which occurs odd number of times?*/%0Apublic class _266 %7B%0A%0A
+public class _266 %7B%0A%0A    public static class Solution1 %7B%0A    
     
@@ -200,16 +200,20 @@
         
+    
 char%5B%5D c
@@ -244,16 +244,20 @@
         
+   
+ 
 Map%3CChar
@@ -294,31 +294,17 @@
 Map%3C
-Character, Integer
 %3E();%0A
+    
     
@@ -338,24 +338,28 @@
             
+ 
+   
 if (!map.con
@@ -381,32 +381,36 @@
                 
+    
 map.put(c, 1);%0A 
@@ -420,16 +420,20 @@
         
+ 
+   
 %7D else %7B
@@ -433,16 +433,20 @@
  else %7B%0A
+    
         
@@ -485,32 +485,36 @@
 1);%0A            
+    
 %7D%0A        %7D%0A    
@@ -499,32 +499,36 @@
       %7D%0A        
+ 
+   
 %7D%0A        int ev
@@ -521,16 +521,20 @@
         
+ 
+   
 int even
@@ -544,16 +544,20 @@
 nt = 0;%0A
+    
         
@@ -621,24 +621,28 @@
             
+ 
+   
 if (e.getVal
@@ -674,16 +674,20 @@
         
+    
 evenCoun
@@ -695,34 +695,42 @@
 ++;%0A            
+ 
-%7D%0A
+   %7D%0A    
             if (
@@ -758,24 +758,28 @@
             
+    
 return false
@@ -784,32 +784,36 @@
 se;%0A            
+    
 %7D%0A        %7D%0A    
@@ -798,34 +798,42 @@
       %7D%0A        
+ 
-%7D%0A
+   %7D%0A    
         return t
@@ -837,16 +837,25 @@
 n true;%0A
+        %7D
 %0A    %7D%0A%0A

refactor 266