美团点评2017年秋招笔试题

xiaoxiao2021-02-28  89

2017/8/31 19:00 - 21:20 输入一串只有1和0的串,截取子串能构成1010或010这样的串(相邻不重复),求构成这样的串的最大长度 例子:输入n 代表输入串的长度 8 输入:1 1 0 0 1 1 0 1 构成的子串:10101 即长度为5 输出:5

import sys if __name__=="__main__": n=int(sys.stdin.readline().strip()) myList2=list(map(int,sys.stdin.readline().strip().split())) resList=[] for i in xrange(1,len(myList2)): j=i-1 if(myList2[j]==myList2[i]) and (i!=n-1): #myList2.remove(myList2[j]) continue else: resList.append(myList2[j]) if(i==(n-1)) and (myList2[j]!=myList2[i]): resList.append(myList2[i]) print("%d" %len(resList))
转载请注明原文地址: https://www.6miu.com/read-58920.html

最新回复(0)