Can you shorten it further (Python)?


  • 0
    S
    from itertools import groupby
    class Solution(object):
        def findMaxConsecutiveOnes(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            ones = [len(x) for x in filter(lambda x: x[0] ==1, [list(g) for i,g in groupby(nums)])]
            if ones:
                return reduce(lambda x,y: max(x,y), ones)
            else:
                return 0
    

  • 0
    V

    """
    from itertools import groupby
    if 1 not in list(set(nums)): return 0
    return len(max(filter(lambda x: x[0]==1, [list(g) for i, g in groupby(nums)])))
    """


Log in to reply
 

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