Anagram Palindrome Python
PROGRAM TO CHECK IF THE GIVEN ANAGRAM STRING CAN BE MADE PALINDROME OR NOT
OUTPUT
No Yes
NO_OF_CHARS = 256 """ function to check whether characters of a string can form a palindrome """def canFormPalindrome(string): # Create a count array and initialize all # values as 0 count = [0 for i in range(NO_OF_CHARS)] # For each character in input strings, # increment count in the corresponding # count array for i in string: count[ord(i)] += 1 # Count odd occurring characters odd = 0 for i in range(NO_OF_CHARS): if (count[i] & 1): odd += 1 if (odd > 1): return False # Return true if odd count is 0 or 1, return True # Driver program to test to print printDups if(canFormPalindrome("geeksforgeeks")): print "Yes" else: print "No"if(canFormPalindrome("geeksogeeks")): print "Yes"else: print "NO"
No Yes
Comments
Post a Comment