Palindrome Permutation
Problem Descriptionβ
Visit LeetCode for the full problem description.
Solutionsβ
Solution 1: C# (Best: 76 ms)β
| Metric | Value |
|---|---|
| Runtime | 76 ms |
| Memory | N/A |
| Date | 2018-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β
| Approach | Time | Space |
|---|---|---|
| Solution | To be analyzed | To be analyzed |