Max Consecutive Ones Given a binary array, find the maximum number of consecutive 1s in this array. example: 1234 Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. 123456789101112 s = [1,1,0,1,1,1,0,1,1,1,1,0,1]s.append(0)print(s)n=m=0for i in range(0,len(s)): if s[i] == 1: n+=1 else: if n > m: m=n n=0print(m) 赞微海报分享
近期评论