Created
January 5, 2017 01:10
-
-
Save jordan-cutler/db53a7c76f230d7869476a903fedb5c8 to your computer and use it in GitHub Desktop.
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 isAnagramOfPalindrome(String test) { | |
HashSet<Character> vals = new HashSet<>(); | |
int length = test.length(); | |
for (int i = 0; i < length; i++) { | |
if (Character.isWhitespace(test.charAt(i))) { | |
// do nothing | |
} | |
else if (vals.contains(test.charAt(i))) { | |
vals.remove(test.charAt(i)); | |
} | |
else { | |
vals.add(test.charAt(i)); | |
} | |
} | |
// by the end of the loop we will have no characters or 1 if we should return true | |
if (vals.size() == 0 || vals.size() == 1) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment