Python one liner using regex


  • 0
    R

    Convert the list into a string and find the number of occurrences of consecutive 1's in the string and return the length of the string. It's a bit slow but it's accepted.

    import re
    class Solution(object):
        def findMaxConsecutiveOnes(self, nums):
             return len(max(re.findall("1*",  "".join(str(i) for i in nums))))
    

Log in to reply
 

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