Skip to main content

Palindrome Permutation

LeetCode Link

Problem Description​

Visit LeetCode for the full problem description.


Solutions​

Solution 1: C# (Best: 76 ms)​

MetricValue
Runtime76 ms
MemoryN/A
Date2018-09-24
Solution
public class Solution {
public bool CanPermutePalindrome(string s) {
HashSet<char> hs = new HashSet<char>();
if (string.IsNullOrEmpty(s)) return false;
int count = 0;
foreach (char c in s)
{
if (hs.Contains(c))
{
hs.Remove(c);
count++;
}
else hs.Add(c);
}

if (hs.Count > 1) return false;
return true;
}
}

Complexity Analysis​

ApproachTimeSpace
SolutionTo be analyzedTo be analyzed