Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean palindromeRearranging(String inputString) {
- if(inputString.length() <= 2) return true;
- char[] stringToArr = inputString.toCharArray();
- Map<Character, Integer> occurancies = new HashMap<Character, Integer>();
- for(char c : stringToArr){
- if(occurancies.containsKey(c)){
- occurancies.put(c, occurancies.get(c) + 1);
- }else {
- occurancies.put(c, 1);
- }
- }
- int strLength = inputString.length();
- int counter = 0;
- for(int i : occurancies.values()){
- if(i % 2 == 0) counter++;
- }
- if(strLength % 2 == 0) return occurancies.size() == counter;
- else return occurancies.size() - 1 == counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement