Accepted Python Solutions beats 97.98% submissions


  • 0
    H

    class Solution(object):
    def findLHS(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """

        disc={}
    
        for num in nums:
            if num in disc:
                disc[num]+=1
            else: disc[num]=1
        
        lenth=0
        for x in disc:
            if x+1 in disc: 
                lenth=max(lenth, disc[x]+disc[x+1])
        return lenth

Log in to reply
 

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