Skip to main content
Back to problems
#266
Easy Algorithms

Palindrome permutation

Hash Table String Bit Manipulation
68.6% acceptance
Mar 31, 2026
1104
75
Given a string s, return true if a permutation of the string could form a palindrome and false otherwise.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn can_permute_palindrome(s: String) -> bool {
    let mut mask: u32 = 0;
    for b in s.bytes() {
      mask ^= 1 << (b - b'a');
    }
    mask.count_ones() <= 1
  }
}