python 判断一串数字里是否有连续的四个 数字

2025-06-24 20:08:09
推荐回答(3个)
回答1:

def isConsecutive4(s):
....s=[int(x) for x in s]
....count,i,tmp = 1,0,s[0]
....while i < len(s) - 1:
........if s[i] == tmp+1:
............count+=1
........else:
............count=1
........if count > 3:return True
........tmp=s[i]
........i+=1
....return False
if __name__ == '__main__':
....print(isConsecutive4('52678908623'))
....print(isConsecutive4('54312234732'))

回答2:

  1. 只看升序吗

  2. 连续多少个?

回答3:

《乾隆抄本百廿回红楼梦稿》,咸丰年间于源题曰“红楼梦稿”,杨继振旧藏,亦称“杨藏本”、“脂稿本”。第78