LC: 266. Palindrome Permutation - spiralgo/algorithms GitHub Wiki

266. Palindrome Permutation:

The Essence:

What we need to focus on:

  • If a string with an even length is a palindrome, every character in the string must always occur an even number of times. palindrome
  • If the string with an odd length is a palindrome, every character except one of the characters must always occur an even number of times.

This is a frequency tracking question.

It means, somehow we need to check if more than one element occurs "odd number" times. If we detect such an element, the string cannot be a palindrome.

Details:

  • We can use a count variable to keep track of the occurrence of any character in the ASCII table.
  • We can also use a map implementation (a HashMap or a custom map implementation based on array)