Skip to content

Instantly share code, notes, and snippets.

@parcar
Created August 22, 2019 14:50
Show Gist options
  • Select an option

  • Save parcar/bdf617a88b9ffd7b3a88e0194bee6664 to your computer and use it in GitHub Desktop.

Select an option

Save parcar/bdf617a88b9ffd7b3a88e0194bee6664 to your computer and use it in GitHub Desktop.
class Solution:
def longestPalindrome(self, s: str) -> int:
ms = set()
count = 0
for i in s:
if i in ms:
ms.discard(i)
count += 2
else:
ms.add(i)
return count if (len(s) <= count) else count + 1
@parcar
Copy link
Author

parcar commented Aug 22, 2019

Runtime: 24 ms, faster than 100.00% of Python3 online submissions for Longest Palindrome.
Memory Usage: 13.9 MB, less than 8.33% of Python3 online submissions for Longest Palindrome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment