Talentd
FleetCode

266. Palindrome Permutation

Easy68.6% acceptance5 companiesPremium elsewhere, free here

Given a string s, return true if a permutation of the string could form a palindrome and false otherwise.

Example 1:

Input: s = "code"
Output: false

Example 2:

Input: s = "aab"
Output: true

Example 3:

Input: s = "carerac"
Output: true

Constraints:

  • 1 <= s.length <= 5000
  • s consists of only lowercase English letters.

Hints open one at a time

Hint 1
Consider the palindromes of odd vs even length. What difference do you notice?
Hint 2
Count the frequency of each character.
Hint 3
If each character occurs even number of times, then it must be a palindrome. How about character which occurs odd number of times?
5:53
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
"code"
Input
"aab"
Input
"carerac"
Your code is saved on this device.Solution