Practice/Meta/Leetcode 266. Palindrome Permutation
CodingOptional
Given a string, determine whether its characters can be rearranged to form a palindrome. You don't need to construct the palindrome itself—just return whether it's possible to create one by reordering the characters.
A palindrome reads the same forwards and backwards. For a string's characters to form a palindrome, the character frequencies must follow specific rules based on whether the resulting palindrome would have even or odd length.
true if any permutation of the input string can form a palindromefalse if no valid palindrome arrangement existsExample 1:
Input: s = "aabb" Output: true Explanation: The characters can be rearranged to form "abba" or "baab", both valid palindromes.
Example 2:
Input: s = "carerac" Output: true Explanation: Can be rearranged to "racecar". The letter 'e' appears once (odd), 'c' twice, 'a' twice, 'r' twice.
Example 3:
Input: s = "code" Output: false Explanation: Each character appears exactly once. We would need at least 3 characters to have matching pairs.
Example 4:
Input: s = "a" Output: true Explanation: A single character is itself a palindrome.