-
-
Save parcar/bdf617a88b9ffd7b3a88e0194bee6664 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.