首页>itarticle>54.back to the longest text string is not simple
54.back to the longest text string is not simple
admin11月 12, 20200
L="caayyhheehhbbbhhjhhyyaac"start,length=0,0foriinrange(1,len(L)-1):ifL[i]==L[i+1]:s=min(len(L[:i+1]),len(L[i+1:]))a,b=1,1whilea<s:ifL[i-a]==L[i+1+a]:# to the left 1 pace, to the right 1 paceb+=1# use b to calculate lengthifb*2>length:start=i+1-b# start = leftlength=b*2# length = from left to rightelse:breaka+=1# use a to countifL[i-1]==L[i+1]:s=min(len(L[:i]),len(L[i+1:]))a,b=1,0whilea<=s:ifL[i-a]==L[i+a]:b+=1if(b*2)+1>length:start=i-blength=b*2+1else:breaka+=1printL[start:start+length]
近期评论