Skip to content

Instantly share code, notes, and snippets.

@deyindra
Last active January 14, 2017 18:36
Show Gist options
  • Save deyindra/edede57358ec10554a9ad2f9bbc0d1dc to your computer and use it in GitHub Desktop.
Save deyindra/edede57358ec10554a9ad2f9bbc0d1dc to your computer and use it in GitHub Desktop.
Given a String return true if any permutation of the String is palindrome
public static boolean isPalinDrome(String str){
if(str==null || str.length()==0){
throw new IllegalArgumentException("Invalid words");
}else{
str = str.trim();
char[] array = str.toCharArray();
Set<Character> sets = new HashSet<>();
for(char ch:array){
boolean add = sets.add(ch);
if(!add){
sets.remove(ch);
}
}
return sets.size()<=1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment