remote87

palindromeRearranging

Apr 17th, 2021
634
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. boolean palindromeRearranging(String inputString) {
  2.    
  3.     if(inputString.length() <= 2) return true;
  4.    
  5.     char[] stringToArr = inputString.toCharArray();
  6.     Map<Character, Integer> occurancies = new HashMap<Character, Integer>();
  7.    
  8.     for(char c : stringToArr){
  9.         if(occurancies.containsKey(c)){
  10.             occurancies.put(c, occurancies.get(c) + 1);
  11.         }else {
  12.             occurancies.put(c, 1);
  13.         }
  14.     }
  15.    
  16.     int strLength = inputString.length();
  17.     int counter = 0;
  18.    
  19.     for(int i : occurancies.values()){
  20.         if(i % 2 == 0) counter++;
  21.     }
  22.    
  23.     if(strLength % 2 == 0) return occurancies.size() == counter;
  24.     else return occurancies.size() - 1 == counter;
  25.    
  26. }
  27.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×