You are viewing a single comment's thread. Return to all comments →
No need to check whether the length of string is even or odd, the second condition i.e. count of ONLY one element should be odd will be enough.
i didn't get it, can you explain it?
In case of aaaabbbb none of the elements have odd occurrence but it has a valid palindrome bbaaaabb.
ya thats the logic....if all elements occur even time then its palindrone.....nd for odd max one aplhabate can have odd no. of occurance....
how can u check that without determing the nature of lenth?pls explain
I have just counted occurence of each letter, and than i summed up numberOfCharOccurrence % 2; if it was greater thatn 1 than we can't have a palindrome of the strin;
But I think if you have the condition of string, you can return 'NO' in the loop of the function earlier.