Very ez Python code using set


  • 0
    W
    class Solution(object):
        def longestPalindrome(self, s):
            """
            :type s: str
            :rtype: int
            """
            a = set()
            for x in s:
            	if x in a :
            		a.remove(x)
            	else :
            		a.add(x)
            return len(s)-len(a) if not a else len(s)-len(a)+1
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.