Python use dictionary beats 99%


  • 1
    class Solution(object):
        def longestPalindrome(self, s):
            dict = {}
            sum = 0
            for i in s:
                if dict.get(i, 0):
                    dict[i] = 0
                    sum += 2
                else:
                    dict[i] = 1
            for j in dict:
                if dict[j] != 0:
                    sum += 1
                    break
            return sum
    

Log in to reply
 

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