Skip to content

Latest commit

 

History

History
125 lines (52 loc) · 1.91 KB

File metadata and controls

125 lines (52 loc) · 1.91 KB

中文文档

Description

Return the largest possible k such that there exists a_1, a_2, ..., a_k such that:

    <li>Each <code>a_i</code> is a non-empty string;</li>
    
    <li>Their concatenation <code>a_1 + a_2 + ... + a_k</code> is equal to <code>text</code>;</li>
    
    <li>For all <code>1 &lt;= i &lt;= k</code>,&nbsp;&nbsp;<code>a_i = a_{k+1 - i}</code>.</li>
    

 

Example 1:

Input: text = "ghiabcdefhelloadamhelloabcdefghi"

Output: 7

Explanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".

Example 2:

Input: text = "merchant"

Output: 1

Explanation: We can split the string on "(merchant)".

Example 3:

Input: text = "antaprezatepzapreanta"

Output: 11

Explanation: We can split the string on "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)".

Example 4:

Input: text = "aaa"

Output: 3

Explanation: We can split the string on "(a)(a)(a)".

 

Constraints:

    <li><code>text</code> consists only of lowercase English characters.</li>
    
    <li><code>1 &lt;= text.length &lt;= 1000</code></li>
    

Solutions

Python3

Java

...