Last active
January 14, 2017 18:36
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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