I think you can do it in O(n). Have two pointers, one a start (char *start = &str[0]) of the string and another at end (char *end = str[strlen(str)]). Scan the string till midway with start moving forward and end moving backward. Compare the character at start and end (*start == *end). If there is a mismatch, output FALSE otherwise TRUE. Hope it helps
On Sun, Jul 24, 2011 at 7:55 PM, UMESH KUMAR <[email protected]>wrote: > Using the all characters of a given String how to specify either > a palindrome or not. > > Ex:- > > 1) String="teste" > After arrange all character we can made a palindrome String as "teset" > So output is TRUE. > > 2)String="hello" > we can not made a palindrome String > output is FALSE > > bool IspalindromePossible (String str) > { > } > > > Thanks > > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Dinesh Bansal The Law of Win says, "Let's not do it your way or my way; let's do it the best way." -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
