Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created December 14, 2011 16:38
Show Gist options
  • Save chadbrewbaker/1477344 to your computer and use it in GitHub Desktop.
Save chadbrewbaker/1477344 to your computer and use it in GitHub Desktop.
Java palindrome anagram detector
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