首页 > 编程知识 正文

leetcode101,leetcode怎么提交

时间:2023-05-06 14:17:34 阅读:136965 作者:4817

交换一个字符,构成最长重复Substring。 将字母按重复段分解为多个Substring(aaabbccaa----AAA、bb、cc、aa ),以每个Substring为对象,最长的Substring之后(或之前) 但是,由于原始String的字符数量有限,因此请在Counter中记录此上限,并在向每个Substring添加相同的字符时不要超过此上限。 此外,如果两个相同字符的Substriing (如aaabaaca和aaabaaa )由一个字符分隔,请尝试使用外部和中间字符进行交换,如aaabaaca最后的a和b。 或者如果有外部相同的字符,则只能交换中间字符和两端的Substring字符。 同样,也可以在Counter中进行限制,看看是否有其他相同两端的Substring文字。

类解决方案: defmaxrepopt1(自、 text : str (-int : char _ counter=collections.counter (text ) repeating=[] I=0whileIlen ) text ) 3360 cur char cunt=1while I1 len (text ) andtext ) i1 )==text ) I ) 3360 cunt=1i=1repeating.appppatid cunt ) ) I=1RES=float(-INF ) ) for char _ and _ numinrepeating : cur char,number=char_and_num[0], cha and char _ counter [ cur char ] (# switchonelettertofollowarepeatinggroup,obtainthelongestsubstringforinrange (1, repeating (1) :prevchar=repeating(I-1 ) [0]prevchar_num=repeating(I-1 ) [1]nextchar=repeating cur char _ num=repeating [ I ] [1] ifprevchar==nextcharandcurchar _ num==13360 # iftwosamecharrepeatingrouparewithouparewithathingroupating andbedevidedbyonlyonedifferentletter、 trytoswitchemiddlechartoformthelongestrepeatingsubstringfromtheoutsidecharorthecharwithintherepeatinggroups.RES=max (mimax )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。