Прошу помочь, что то туплю и не понимаю в чем печаль... По второму пункту не хочет проходить..
package com.javarush.task.task39.task3908;
/*
Возможен ли палиндром?
*/
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static void main(String[] args) {
System.out.println(isPalindromePermutation("a") + " true");
System.out.println(isPalindromePermutation("aa") + " true");
System.out.println(isPalindromePermutation("aba") + " true");
System.out.println(isPalindromePermutation("abab") + " true");
System.out.println(isPalindromePermutation("asssab") + " false");
}
public static boolean isPalindromePermutation(String s) {
if(s==null || s.length()==0) return false;
if(s.length()<3)return true;
Map<String,Integer> map = new HashMap<>();
for(int i = 0;i<s.length();i++) {
String key = s.substring(i, i + 1).toLowerCase();
Integer x = map.get(key);
if (x == null) {
x = 1;
} else {
x++;
}
map.put(key, x);
}
int kolNech = 0;
for(Map.Entry<String,Integer> entry: map.entrySet()){
if(entry.getValue()%2!=0){
kolNech++;
}}
return kolNech <= 1;
}
}