remote87

palindromeRearranging better

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

×