小慕正在处理一个字符串项目。他有一个字符串 `s`,需要从中找出一个,要求满足以下两个条件: 1. 该子串中的任意一个字符最多出现 `2` 次; 2. 该子串; 小慕需要你帮他找出满足该条件的最长子串的长度。
提示:带虚线的词点一下有通俗解释。
输入描述
<p> <br /> </p> <p style="white-space-collapse:preserve;"> 第一行为要求不包含的指定字符,为单个字符,取值范围 <code>[0-9a-zA-Z]</code> </p> <p style="white-space-collapse:preserve;"> 第二行为字符串 s,每个字符范围 <code>[0-9a-zA-Z]</code>,长度范围 <code>[1,10000]</code> </p> <p> <br /> </p> <span data-lark-record-data="{"rootId":"DfZdd5d1nor9CExg7sVck1zenae","text":{"initialAttributedTexts":{"text":{"0":"第一行为要求不包含的指定字符,为单个字符,取值范围 [0-9a-zA-Z]\n第二行为字符串 s,每个字符范围 [0-9a-zA-Z],长度范围 [1,10000]"},"attribs":{"0":"*0+q*0*1+b*0|1+1*0+h*0*1+b*0+6*0*1+9"}},"apool":{"numToAttrib":{"0":["author","7115054903550050305"],"1":["inlineCode","true"]},"nextNum":2}},"type":"text","referenceRecordMap":{},"extra":{"mention_page_title":{},"external_mention_url":{}},"isKeepQuoteContainer":false,"isFromCode":false,"selection":[{"id":9,"type":"text","selection":{"start":0,"end":81},"recordId":"UK62duAQioiaOmxiLgGc132Rn95"}],"payloadMap":{},"isCut":false}" data-lark-record-format="docx/text" class="lark-record-clipboard"></span>
输出描述
<p> <br /> </p> <p style="white-space-collapse:preserve;"> 一个整数,满足条件的最长子串的长度; </p> <p style="white-space-collapse:preserve;"> 如果不存在满足条件的子串,则返回 <code>0</code> </p> <p> <br /> </p> <span data-lark-record-data="{"rootId":"DfZdd5d1nor9CExg7sVck1zenae","text":{"initialAttributedTexts":{"text":{"0":"一个整数,满足条件的最长子串的长度;\n如果不存在满足条件的子串,则返回 0"},"attribs":{"0":"*0|1+j*0+h*0*1+1"}},"apool":{"numToAttrib":{"0":["author","7115054903550050305"],"1":["inlineCode","true"]},"nextNum":2}},"type":"text","referenceRecordMap":{},"extra":{"mention_page_title":{},"external_mention_url":{}},"isKeepQuoteContainer":false,"isFromCode":false,"selection":[{"id":11,"type":"text","selection":{"start":0,"end":37},"recordId":"FCu6d4WQUo62IAxO4kkc6SQnnhe"}],"payloadMap":{},"isCut":false}" data-lark-record-format="docx/text" class="lark-record-clipboard"></span>
示例
示例 1
输入
D ABACD1231
输出
4
时间限制 1000 ms · 内存限制 128 MB