Created
December 14, 2011 16:38
-
-
Save chadbrewbaker/1477344 to your computer and use it in GitHub Desktop.
Java palindrome anagram detector
This file contains 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 boolean isPalindromeAnagram(String s){ | |
//assuming this is initalized to zero | |
boolean bvec[] = new boolean[90]; | |
// ' ' is ASCII 32 | |
// 'z' is ASCII 122 | |
// So -32 to base at zero and length 90 | |
for(int i=0;i<s.length();i++){ | |
bvec[(int)s.charAt(i)-32] ^= true; | |
} | |
int odds =0; | |
for(int i=0;i<90;i++){ | |
if(bvec[i]){ | |
odds++; | |
if(odds>1) | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment