Skip to main content

409 - Longest Palindrome

Details

KeyValue
Linkhttps://leetcode.com/problems/longest-palindrome/
LanguagePython 3
Runtime71 ms, faster than 8.40% of Python3 online submissions for Longest Palindrome
Memory Usage13.8 MB, less than 97.58% of Python3 online submissions for Longest Palindrome
DatastructuresSeen-Hash
AlgorithmsIterate + Seen-Hash
ComplexityTime: O(n) Memory: O(1)

Procedure

  1. ...

Code

hash = set()
for c in s:
if c not in hash:
hash.add(c)
else:
hash.remove(c)
# len(hash) is the number of the odd letters
return len(s) - len(hash) + 1 if len(hash) > 0 else len(s)